Advertisement
Guest User

Untitled

a guest
Apr 15th, 2014
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. /**
  2. * Created by wilson on 2/25/2014.
  3. */
  4. import java.util.Scanner;
  5. public class GradesDemo {
  6. public static void main(String[] args) {
  7. Grades grade = new Grades();
  8. String name;
  9. double score = 0;
  10. boolean invalid = true;
  11. Scanner keyboard = new Scanner(System.in);
  12. //One loop iteration for each student
  13.  
  14. for (int i = 0; i < 5; i++) {
  15. invalid = true;
  16. //Asks for student name, and stores to array
  17. System.out.println("Student's Name:");
  18. name = keyboard.nextLine();
  19. grade.setName(name, i);
  20.  
  21. //while loop to check if score entered by user is valid
  22. while (invalid == true) {
  23. System.out.println("Student's Score:");
  24. score = keyboard.nextDouble();
  25. //Check if score entered was valid. If not, user will be asked again
  26. if (score >= 0 && score <= 100)
  27. invalid = false;
  28. else
  29. System.out.println("Score is invalid. Must be between 0-100. Try again.");
  30. }
  31. grade.setScore(score, i);
  32. //Calculate grade
  33. grade.findGrade(i);
  34. }
  35.  
  36. for (int i = 0; i <5; i++) {
  37. System.out.println(grade.toString(i));
  38. }
  39. }
  40. }
  41.  
  42. Student's Name:
  43. John Doe
  44. Student's Score:
  45. 88
  46. Student's Name:
  47. Student's Score:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement