Advertisement
Nick-O-Rama

UPDATEteststudentrecord

Dec 2nd, 2014
489
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.90 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.io.*;
  3. public class TestStudentRecord {
  4.  
  5.     public static void main(String[] args) throws IOException {
  6.        
  7.         File myFile = new File("records.txt");
  8.         Scanner input = new Scanner(myFile);
  9.         Scanner user_input = new Scanner(System.in);
  10.        
  11.         StudentRecord[] records = new StudentRecord[20];
  12.         for (int i = 0; i < records.length; i++)
  13.         {
  14.             records[i] = new StudentRecord(String.valueOf(input.nextInt()), input.nextInt(), input.nextDouble(), input.nextDouble(), input.nextDouble(), input.nextDouble());
  15.         }
  16.         input.close();
  17.         int num;
  18.         do
  19.         {
  20.             System.out.println(printMenu());
  21.             num = user_input.nextInt();
  22.         } while (num < 1 || num > 5);
  23.         user_input.nextLine();
  24.         switch (num)
  25.         {
  26.             case 1:
  27.                 for (StudentRecord student: records)
  28.                 {
  29.                     System.out.println(student.getStudentID());
  30.                 }
  31.                 break;
  32.             case 2:
  33.                 for (StudentRecord student: records)
  34.                 {
  35.                     System.out.println(student.getLetterGrade());
  36.                 }
  37.                 break;
  38.             case 3:
  39.                 for (StudentRecord student: records)
  40.                 {
  41.                     System.out.println((int)(student.getNumericGrade()*100) + "%");
  42.                 }
  43.                 break;
  44.             case 4:
  45.                 System.out.println("Enter a student ID: ");
  46.                 String user_id = user_input.nextLine();
  47.                 for (int i = 0; i < records.length; i++)
  48.                 {
  49.                     if (user_id.equals(records[i].getStudentID()))
  50.                     {
  51.                         System.out.println(records[i].toString());
  52.                     }
  53.                 }
  54.                 break;
  55.             default:
  56.                 System.out.println("Goodbye");
  57.                 System.exit(0);
  58.         }
  59.        
  60.  
  61.        
  62.  
  63.     }
  64.  
  65.  
  66.     public static String printMenu()
  67.     {
  68.         return "1 - Display all Ids\n"
  69.                 + "2 - Display letter grade for all students\n"
  70.                 + "3 - Display numeric average for all students\n"
  71.                 + "4 - Search and display 1 student record\n"
  72.                 + "5 - Exit";
  73.     }
  74.    
  75.    
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement