Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner; // import Java utility known as the Scanner variable type for the later use of user input
- public class GradeBookV2 {
- public static void main(String[] args) {
- // ------------------ Declaring variables -------------------- \\
- Scanner keybd = new Scanner(System.in); // This will create a Scanner type class for the user's input
- String course_prefix = ""; // the name of the course in a prefix format (ABC 1234)
- double score1;
- double score2; // The 3 test scores for each course
- double score3;
- double average = 0; // the Average of the 3 test scores, and therefore, the grade for the course grade in percentage format.
- String letterGrade = ""; // A,B,C,D,F
- double gradePoint = 0.0; // 4.0, 3.0, 2.0, 1.0
- double GPA = 0.0;
- String output = "";
- // ----------------- Startup prompt of the program --------------- \\
- System.out.println("Welcome to GradeBook!");
- System.out.println("This program will list your course grades in three different formats, along with your semester GPA.");
- System.out.println("Please note: Enter your courses through a prefix format (Ex: CUS 1115) and your grades through an integer format (Ex: 95).");
- // ---------------------------- Task (Loop) --------------------------- \\
- for (int course = 1; course <= 4; course++)
- {
- {
- System.out.println("\nEnter the course prefix for Course " + course + ":");
- course_prefix = keybd.nextLine();
- System.out.println("Enter the three test scores for the course: ");
- score1 = keybd.nextDouble();
- score2 = keybd.nextDouble();
- score3 = keybd.nextDouble();
- keybd.nextLine();
- average = (score1 + score2 + score3) / 3.0;
- 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
- }
- // if Statements:
- if (average >= 90)
- {
- letterGrade = "A";
- gradePoint = 4.0;
- }
- else if (average >= 80)
- {
- letterGrade = "B";
- gradePoint = 3.0;
- }
- else if (average >= 70)
- {
- letterGrade = "C";
- gradePoint = 2.0;
- }
- else if (average >= 60)
- {
- letterGrade = "D";
- gradePoint = 1.0;
- }
- else if (average < 60)
- {
- letterGrade = "F";
- gradePoint = 0.0;
- }
- // ---------------------------------------------------- Result Output -------------------------------------------------------- \\
- String lines = ("\n%-8s%17.2f%15s%20s");
- output += String.format(lines, course_prefix, average, letterGrade, gradePoint); // OR: output = output + String.format(format, course_prefix......)
- } // <---- End of for-loop
- // The Line 0 represents the titles for each section displayed:
- String line_0 = ("\n%-6s%20s%20s%20s");
- System.out.printf(line_0 , "Course" , "Average", "Letter Grade", "Grade Points");
- // The output variable displays the information for all 4 courses below:
- System.out.println(output);
- GPA = GPA / 4.0;
- System.out.println("\nGPA: " + GPA);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement