fork download
  1. import java.util.Scanner;
  2. public class asg06
  3. {
  4.  
  5. public static void main(String[] args)
  6. {
  7. Scanner stdin = new Scanner(System.in);
  8. //declarations
  9. int numberOfStudents;
  10. double scoreAverage;
  11. double maxScore = 0;
  12. double scoreCheck;
  13. int end = 0;
  14. double choice;
  15. double sum = 0;
  16. double chosenStudent;
  17. //how many students are there
  18. System.out.println("How many students were in the class?");
  19. numberOfStudents = stdin.nextInt();
  20. //gather info into arrays
  21. double iD[] = new double[numberOfStudents];
  22. String firstName[] = new String[numberOfStudents];
  23. String lastName[] = new String[numberOfStudents];
  24. double scores[] = new double[numberOfStudents];
  25. for (int i = 0; i < iD.length; i++)
  26. {
  27. while (iD[i] <= i)
  28. {
  29. System.out.println("Please enter the students ID");
  30. iD[i] = stdin.nextInt();
  31. System.out.println("What is the students first name?");
  32. firstName[i] = stdin.next();
  33. System.out.println("What is the students last name?");
  34. lastName[i] = stdin.next();
  35. boolean valid = false;
  36. while (valid == false)
  37. {
  38. System.out.println("What is the students score?");
  39. scoreCheck = stdin.nextDouble();
  40. if(scoreCheck < 0)
  41. System.out.println("Score must be at least 0");
  42. else if (scoreCheck > 100)
  43. System.out.println("Score cannot be greater than 100");
  44. else
  45. scores[i] = scoreCheck;
  46. sum += scoreCheck;
  47. valid = true;
  48. }
  49. }
  50. }
  51. scoreAverage = sum / numberOfStudents;
  52. maxScore = max(scores);
  53. System.out.println("Thank you. The highest score is " + maxScore + " and the average score was " + scoreAverage + ".");
  54. //searching students
  55. System.out.println("You may now exit the program by entering 0 or search for a student by ID number");
  56. while(end == 0)
  57. {
  58. System.out.println("What would you like to do?");
  59. choice = stdin.nextDouble();
  60. if (choice == 0)
  61. {
  62. end = 1;
  63. }
  64. else
  65. {
  66. //this part is pretty broken. I know how its supposed to work (kind of) but i'm having trouble pulling the correct info from my methods
  67. int i = 0;
  68. i = search(iD, choice);
  69. chosenStudent = i;
  70. if (chosenStudent == -1)
  71. {
  72. System.out.println("This student was not found, please re-enter the student id or enter 0 to quit");
  73. }
  74. else
  75. {
  76. if (scores[i] == maxScore)
  77. {
  78. System.out.println("Student number " + iD[i] + ", " + firstName[i] + " " + lastName[i] + ", received a score of " + scores[i] + "which is the maximum score!");
  79. }
  80. else if (scores[i] == scoreAverage)
  81. {
  82. System.out.println("Student number " + iD[i] + ", " + firstName[i] + " " + lastName[i] + ", received a score of " + scores[i] + "which is the average.");
  83. }
  84. else if (scores[i] < scoreAverage)
  85. {
  86. System.out.println("Student number " + iD[i] + ", " + firstName[i] + " " + lastName[i] + ", received a score of " + scores[i] + "which is " + (scoreAverage - scores[i]) + "less than the average.");
  87. }
  88. else if (scores[i] > scoreAverage)
  89. {
  90. System.out.println("Student number " + iD[i] + ", " + firstName[i] + " " + lastName[i] + ", received a score of " + scores[i] + "which is " + (scores[i] - scoreAverage) + "more than the average.");
  91. }
  92.  
  93. }
  94. }
  95. }
  96. stdin.close();
  97. }
  98. //Max Score Method
  99. public static double max(double scores[])
  100. {
  101. double maxScore = 0;
  102. for (int i = 1; i < scores.length; i++)
  103. {
  104. if (scores[i] > maxScore)
  105. {
  106. maxScore = scores[i];
  107. }
  108.  
  109.  
  110. }
  111. return maxScore;
  112. }
  113.  
  114. public static int search(double iD[], double choice)
  115. {
  116. for (int i = 0; i < iD.length; i++)
  117. {
  118. if ( iD[i] == choice )
  119. return i;
  120. }
  121. return -1;
  122. }
  123. }
  124.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:2: class asg06 is public, should be declared in a file named asg06.java
public class asg06 
       ^
1 error
stdout
Standard output is empty