Advertisement
Guest User

Untitled

a guest
Jul 20th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. /**
  4. This program demonstrates a solution to the
  5. Grade Book programming challenge.
  6. */
  7.  
  8. public class GradeBookDemo2
  9. {
  10. public static void main(String[] args)
  11. {
  12. // Create a GradeBook object.
  13. GradeBook gb = new GradeBook();
  14.  
  15. // Get the data from the user.
  16. getData(gb);
  17.  
  18. // Display the student data.
  19. System.out.println("STUDENT DATA");
  20. for (int i = 1; i <= 5; i++)
  21. {
  22. System.out.println("Name : " + gb.getName(i) +
  23. "\tAverage score: " +
  24. gb.getAverage(i) +
  25. "\tGrade: " +
  26. gb.getLetterGrade(i));
  27. }
  28. }
  29.  
  30. /**
  31. The getData method gets student data from the user
  32. and populates a GradeBook object.
  33. @param gb The GradeBook object.
  34. */
  35.  
  36. public static void getData(GradeBook gb)
  37. {
  38. String name; // To hold a name
  39. double[] scores = new double[4]; // An array of scores
  40.  
  41. // Create a Scanner object for keyboard input.
  42. Scanner keyboard = new Scanner(System.in);
  43.  
  44. // Get info for each student.
  45. for (int student = 1; student <= 5; student++)
  46. {
  47. // Get the name.
  48. System.out.print("Enter student " + student +
  49. "'s name: ");
  50. name = keyboard.nextLine();
  51. gb.setName(student, name);
  52.  
  53. // Read the 4 test scores.
  54. System.out.println("Now enter student " + student +
  55. "'s four test scores.");
  56. for (int i = 0; i < 4; i++)
  57. {
  58. System.out.print("Test score #" + (i + 1) + ": ");
  59. scores[i] = keyboard.nextDouble();
  60. gb.setScores(student, scores);
  61. }
  62.  
  63. // Consume the remaining newline.
  64. keyboard.nextLine();
  65. }
  66.  
  67. System.out.println();
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement