Question #59495

Create an application that allows you to enter student data that consists of an ID number, first name, last name, and grade point average. Depending on whether the student's grade point average is at least 2.0, output each record either to a file of students in good standing or those on academic probation. Save the program as StudentStanding.java.

Expert's answer

Answer on Question #59495, Programming & Computer Science, Java, JSP, JSF

Condition

Create an application that allows you to enter student data that consists of an ID number, first name, last name, and grade point average. Depending on whether the student's grade point average is at least 2.0, output each record either to a file of students in good standing or those on academic probation. Save the program as StudentStanding.java.

Code

import java.io.*;
import java.util.Locale;
import java.util.Scanner;
public class StudentStanding {
    public static void main(String[] args) throws IOException {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        Scanner scanner = new Scanner(System.in).useLocale(Locale.US);
        boolean isWorking = true;
        while (isWorking) {
            System.out.print("ID: ");
            int id = scanner.nextInt();
            System.out.print("First name: ");
            String firstName = bufferedReader.readLine();
            System.out.print("Last name: ");
            String lastName = bufferedReader.readLine();
            System.out.print("Grade point average: ");
            double gradePointAverage = scanner.nextDouble();
            System.out.println("Student " + firstName + " " + lastName + " with ID " + id + " have " + gradePointAverage + " grade point average.");
            if (gradePointAverage >= 2.0) {
                BufferedWriter out = new BufferedWriter(new FileWriter("D:\\GoodStanding.txt", true));
                out.write("ID: " + Integer.toString(id));
                out.newLine();
                out.write("First name: " + firstName);
                out.newLine();
                out.write("Last name: " + lastName);
                out.newLine();
                out.write("Grade point average: " + Double.toString(gradePointAverage));
                out.newLine();
                out.newLine();
                out.close();
                System.out.println(firstName + " " + lastName + " have grade point average > 2.0");
                System.out.println("This student was saved to GoodStanding.txt");
            } else {
                BufferedWriter out = new BufferedWriter(new FileWriter("D:\\AcademicProbation.txt", true));
                out.write("ID: " + Integer.toString(id));
                out.newLine();
                out.write("First name: " + firstName);
                out.newLine();
                out.write("Last name: " + lastName);
                out.newLine();
                out.write("Grade point average: " + Double.toString(gradePointAverage));
                out.newLine();
                out.newLine();
                out.close();
                System.out.println(firstName + " " + lastName + " have grade point average < 2.0");
                System.out.println("This student was saved to AcademicProbation.txt");
            }
            System.out.println("Continue? y - yes, n - no.");
            System.out.print("Answer: ");
            String answer = bufferedReader.readLine();
            if (answer.equals("y")) {
                System.out.println("");
            } else if (answer.equals("n")) {
                scanner.close();
                isWorking = false;
            }
        }
        System.out.println("Finished");
    }
}


Output

ID: 1

First name: FirstName1

Last name: LastName1

Grade point average: 4.5

Student FirstName1 LastName1 with ID 1 have 4.5 grade point average.

FirstName1 LastName1 have grade point average > 2.0

This student was saved to GoodStanding.txt

Continue? y - yes, n - no.

Answer: y

ID: 2

First name: FirstName2

Last name: LastName2

Grade point average: 2.6

Student FirstName2 LastName2 with ID 2 have 2.6 grade point average.

FirstName2 LastName2 have grade point average > 2.0

This student was saved to GoodStanding.txt

Continue? y - yes, n - no.

Answer: y

ID: 3

First name: FirstName3

Last name: LastName3

Grade point average: 1.4

Student FirstName3 LastName3 with ID 3 have 1.4 grade point average.

FirstName3 LastName3 have grade point average < 2.0

This student was saved to AcademicProbation.txt

Continue? y - yes, n - no.

Answer: n

Finished

http://www.AssignmentExpert.com/

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS