Guest User

GradPart3

a guest
Jul 17th, 2018
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. package nestedForWhile;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class graduartionPart3 {
  6. public static void main(String[] args){
  7. Scanner scanner = new Scanner(System.in);
  8. String name = scanner.nextLine();
  9. double notPassed = 0;
  10. double sum = 0;
  11. double course = 1;
  12.  
  13. while(true){
  14. if(name.equalsIgnoreCase("end")){
  15. break;
  16. }
  17.  
  18. //double grade = Double.parseDouble(scanner.nextLine());
  19.  
  20. while(course <= 12 && notPassed < 2){
  21. double grade = Double.parseDouble(scanner.nextLine());
  22. if(grade >= 4){
  23. sum += grade;
  24. course++;
  25. }
  26. else{
  27. notPassed+= 1;
  28. }
  29.  
  30. }
  31. name = scanner.nextLine();
  32. }
  33.  
  34. double averageGrade = sum / 12;
  35.  
  36. if(averageGrade >= 4){
  37. System.out.printf("%s graduated. Average grade: %.2f", name, averageGrade);
  38. }else{
  39. System.out.printf("%s has been excluded at grade %d", name, notPassed);
  40. }
  41.  
  42.  
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment