Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.io.*;
- public class TestStudentRecord {
- public static void main(String[] args) throws IOException {
- File myFile = new File("records.txt");
- Scanner input = new Scanner(myFile);
- Scanner user_input = new Scanner(System.in);
- StudentRecord[] records = new StudentRecord[20];
- for (int i = 0; i < records.length; i++)
- {
- records[i] = new StudentRecord(String.valueOf(input.nextInt()), input.nextInt(), input.nextDouble(), input.nextDouble(), input.nextDouble(), input.nextDouble());
- }
- input.close();
- int num;
- do
- {
- System.out.println(printMenu());
- num = user_input.nextInt();
- } while (num < 1 || num > 5);
- user_input.nextLine();
- switch (num)
- {
- case 1:
- for (StudentRecord student: records)
- {
- System.out.println(student.getStudentID());
- }
- break;
- case 2:
- for (StudentRecord student: records)
- {
- System.out.println(student.getLetterGrade());
- }
- break;
- case 3:
- for (StudentRecord student: records)
- {
- System.out.println((int)(student.getNumericGrade()*100) + "%");
- }
- break;
- case 4:
- System.out.println("Enter a student ID: ");
- String user_id = user_input.nextLine();
- for (int i = 0; i < records.length; i++)
- {
- if (user_id.equals(records[i].getStudentID()))
- {
- System.out.println(records[i].toString());
- }
- }
- break;
- default:
- System.out.println("Goodbye");
- System.exit(0);
- }
- }
- public static String printMenu()
- {
- return "1 - Display all Ids\n"
- + "2 - Display letter grade for all students\n"
- + "3 - Display numeric average for all students\n"
- + "4 - Search and display 1 student record\n"
- + "5 - Exit";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement