Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.22 KB | None | 0 0
  1. import java.util.Scanner; // import Java utility known as the Scanner variable type for the later use of user input
  2.  
  3. public class GradeBookV2 {
  4.  
  5.     public static void main(String[] args) {
  6.        
  7.                             // ------------------ Declaring variables -------------------- \\
  8.        
  9.         Scanner keybd = new Scanner(System.in); // This will create a Scanner type class for the user's input
  10.        
  11.         String course_prefix = "";                          // the name of the course in a prefix format (ABC 1234)
  12.        
  13.        
  14.         double score1;
  15.         double score2;                                      // The 3 test scores for each course
  16.         double score3;
  17.        
  18.         double average = 0;                                 // the Average of the 3 test scores, and therefore, the grade for the course grade in percentage format.
  19.         String letterGrade = "";                            // A,B,C,D,F
  20.         double gradePoint = 0.0;                            // 4.0, 3.0, 2.0, 1.0
  21.         double GPA = 0.0;
  22.        
  23.         String output = "";
  24.        
  25.        
  26.        
  27.                         // ----------------- Startup prompt of the program --------------- \\
  28.  
  29.         System.out.println("Welcome to GradeBook!");
  30.         System.out.println("This program will list your course grades in three different formats, along with your semester GPA.");
  31.         System.out.println("Please note: Enter your courses through a prefix format (Ex: CUS 1115) and your grades through an integer format (Ex: 95).");
  32.        
  33.        
  34.                        // ---------------------------- Task (Loop) --------------------------- \\
  35.        
  36.        
  37.         for (int course = 1; course <= 4; course++)
  38.         {
  39.             {
  40.                 System.out.println("\nEnter the course prefix for Course " + course + ":");
  41.                 course_prefix = keybd.nextLine();
  42.                
  43.                 System.out.println("Enter the three test scores for the course: ");
  44.                 score1 = keybd.nextDouble();
  45.                 score2 = keybd.nextDouble();
  46.                 score3 = keybd.nextDouble();
  47.                
  48.                 keybd.nextLine();
  49.                
  50.                 average = (score1 + score2 + score3) / 3.0;
  51.                 GPA = (GPA + gradePoint) + 0.25;    // <--- *I don't know what's wrong with the program! It keeps giving me a Semester GPA value of 0.25 less than what it's actually supposed to be
  52.                
  53.             }
  54.    
  55.        
  56.     // if Statements:
  57.            
  58.             if (average >= 90)
  59.             {
  60.                 letterGrade = "A";
  61.                 gradePoint = 4.0;
  62.             }
  63.            
  64.             else if (average >= 80)
  65.             {
  66.                 letterGrade = "B";
  67.                 gradePoint = 3.0;
  68.             }
  69.                
  70.             else if (average >= 70)
  71.             {
  72.                 letterGrade = "C";
  73.                 gradePoint = 2.0;
  74.             }
  75.            
  76.             else if (average >= 60)
  77.             {
  78.                 letterGrade = "D";
  79.                 gradePoint = 1.0;
  80.             }
  81.            
  82.             else if (average < 60)
  83.             {
  84.                 letterGrade = "F";
  85.                 gradePoint = 0.0;
  86.             }
  87.  
  88.            
  89.                 // ---------------------------------------------------- Result Output -------------------------------------------------------- \\
  90.            
  91.             String lines = ("\n%-8s%17.2f%15s%20s");
  92.             output += String.format(lines, course_prefix, average, letterGrade, gradePoint);    // OR: output = output + String.format(format, course_prefix......)
  93.            
  94.         }       // <---- End of for-loop
  95.        
  96.        
  97.         // The Line 0 represents the titles for each section displayed:
  98.             String line_0 = ("\n%-6s%20s%20s%20s");
  99.             System.out.printf(line_0 , "Course" , "Average", "Letter Grade", "Grade Points");
  100.        
  101.         // The output variable displays the information for all 4 courses below:
  102.             System.out.println(output);
  103.            
  104.             GPA = GPA / 4.0;
  105.             System.out.println("\nGPA: " + GPA);
  106.     }
  107.  
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement