58.5k views
2 votes
Write a Java application that allows a user to enter student data that consists of a Student number, First name, Surname, and average assignment mark. Depending on whether the students average assignment mark is at least 40, output each record either to a file of students who passed (call it pass.txt) or students qualifying for supplementary (call it supp.txt).​

User Lidy
by
4.8k points

1 Answer

2 votes

Answer:

Following are the given code to the given question:

import java.io.*;//import package

import java.util.*;//import package

public class Main //defining a class Main

{

public static void main(String[] args) throws IOException//defining main method

{

Scanner obx = new Scanner(System.in);//creating Scanner class object

System.out.println("Enter Student Number: ");//print message

long studentNumber = obx.nextLong();//defining a studentNumber that input value

obx.nextLine();//use for next line

System.out.println("Enter Your First Name:");//print message

String name = obx.nextLine();//input value

System.out.println("Enter Your Surname:");//print message

String surName = obx.nextLine();//input value

System.out.println("Enter Your Average Assisgnment Marks:");//print message

int avgAssignMarks = obx.nextInt();//input value

if(avgAssignMarks>=50)//use if to check Average value greater than equal to 50

{

FileWriter fw = new FileWriter("pass.txt", true);//creating FileWriter object

PrintWriter out = new PrintWriter(fw);//creating PrintWriter object

out.println("Student Number: "+studentNumber);//print message with value

out.println("Student Name: "+name);//print message with value

out.println("Student Surname: "+surName);//print message with value

out.println("Student Average Assignmet Marks: "+avgAssignMarks);//print message with value

out.println("=================================================");

out.close();

}

else//else block

{

FileWriter fw = new FileWriter("supp.txt", true);//creating FileWriter object

PrintWriter out = new PrintWriter(fw);//creating PrintWriter object

out.println("Student Number: "+studentNumber);//print message with value

out.println("Student Name: "+name);//print message with value

out.println("Student Surname: "+surName);//print message with value

out.println("Student Average Assignmet Marks: "+avgAssignMarks);//print message with value

out.println("=================================================");

out.close();

}

}

}

Output:

Please find the attached file.

Step-by-step explanation:

In this code, a class "Main" is declared inside the class main method is declared inside the main method a scanner class, FileWriter, and PrintWriter object is creating that defines the string and long variable which is used to input value from the user-end, and store the value into the pass.txt file.

Write a Java application that allows a user to enter student data that consists of-example-1
User Richard Lindhout
by
4.5k points