Advertisement
binibiningtinamoran

GPA Calculator

Apr 10th, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.11 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class GPACalculator {
  4.  
  5.     public static void main(String []args) {
  6.  
  7.         Scanner scan = new Scanner(System.in);
  8.         int numberOfStudents = 1;
  9.         double studentGPA;
  10.         int numberOfGPABelowTwo = 0;
  11.  
  12.         System.out.println();
  13.  
  14.         do {
  15.  
  16.             System.out.print("Enter student GPA for Student #" + numberOfStudents + " or (-1) to " +
  17.                     "exit" + ": ");
  18.             studentGPA = scan.nextDouble();
  19.  
  20.             while (studentGPA < -1) {
  21.                 System.out.println("Invalid GPA value.");
  22.                 System.out.print("Enter student GPA for Student #" + numberOfStudents + ": ");
  23.                 studentGPA = scan.nextDouble();
  24.             }
  25.  
  26.             if (studentGPA <= 2.0 && studentGPA != -1) {
  27.                 numberOfGPABelowTwo++;
  28.             }
  29.             numberOfStudents++;
  30.  
  31.         } while (studentGPA != -1);
  32.  
  33.         System.out.printf("%,d %s", numberOfGPABelowTwo, numberOfGPABelowTwo > 1 ? "students " +
  34.                 "have warnings." : "student has a warning.");
  35.  
  36.     } // end main
  37. } // end class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement