Advertisement
Guest User

Student.java

a guest
May 9th, 2016
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3. public class Student {
  4.  
  5. public static void main(String args[]) throws IOException
  6. {
  7. Scanner scan = new Scanner(System.in);
  8. Scanner file = new Scanner(new File("FinalExamDataFile.txt"));
  9.  
  10. List<String> FirstName = new ArrayList<String>();
  11. List<String> LastName = new ArrayList<String>();
  12. List<String> IDNumber = new ArrayList<String>();
  13. List<Integer> Average = new ArrayList<Integer>();
  14.  
  15. //initiating all of the counters in the program
  16. int j;
  17. int above70 = 0;
  18. int below70 = 0;
  19.  
  20. //counters for the for loops
  21. int average = 0;
  22.  
  23. for(int i=0; i<2; i++){
  24.  
  25. int sum = 0;
  26. System.out.println("Enter the Student's first name");
  27. FirstName.add(scan.next());
  28.  
  29. System.out.println("Enter the student's last name");
  30. LastName.add(scan.next());
  31.  
  32. System.out.println("Enter the student's ID number");
  33. IDNumber.add(scan.next());
  34.  
  35. System.out.println("Enter up to 15 grades, enter -1 to finish.");
  36.  
  37. //adds up all 15 grades then divides them by 15 to get the student's average
  38. for(j=0; j<3; j++){
  39. int score = scan.nextInt();
  40. if (score > 100)
  41. {
  42. System.out.println("The score must be between 0-100");
  43. j--;
  44. }
  45. else if (score >= 0){
  46. sum = sum + score;
  47. }
  48. else if (score <= 0){
  49. System.out.println("The score must be between 0-100");
  50. j--;
  51. }
  52. else if (score == -1)
  53. {
  54. System.out.println("Thank you.");
  55. break;
  56. }
  57. }
  58. //takes the average of the 15 grades and adds to the "average" array
  59. Average.add(sum / j);
  60. if(sum/j >= 70){
  61. above70++;
  62. }
  63. else{ below70++; }
  64. }
  65.  
  66. //allows user to call on a student to see their grade
  67. for(int k=0; k < k+1; k++){
  68. System.out.println("Enter the student's first name, last name, or ID Number to see their results");
  69. String search = scan.next();
  70. int index;
  71. index = FirstName.indexOf(search);
  72. index = LastName.indexOf(search);
  73. index = IDNumber.indexOf(search);
  74. if(FirstName.contains(search) || LastName.contains(search) || IDNumber.contains(search)){
  75. System.out.println("Student: " + FirstName.get(index) + " " + LastName.get(index) + " " +
  76. IDNumber.get(index) + "\nStudent's Average: " + Average.get(index));
  77. }
  78. else{
  79. System.out.println("The student was not found.");
  80. }
  81. }
  82.  
  83. //reading the file goes here
  84.  
  85. }
  86.  
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement