Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class GradeCalculator {
- public static void main(String[] args) {
- //declaring the variables WEIGHT
- int exam1Weight, exam2Weight;
- int finalExamWeight, labWeight;
- int projectWeight, attendanceWeight, quizWeight;
- //initialize
- exam1Weight = 0;
- exam2Weight = 0;
- finalExamWeight = 0;
- labWeight = 0;
- projectWeight = 0;
- attendanceWeight = 0;
- quizWeight = 0;
- //declaring the variable SCORE
- int exam1Score, exam2Score, finalExamScore;
- int labScore, projectScore, attendanceScore, quizScore;
- //initialize
- exam1Score = 0;
- exam2Score = 0;
- finalExamScore = 0;
- labScore = 0;
- projectScore = 0;
- attendanceScore = 0;
- quizScore = 0;
- //scanner for inputs
- Scanner keyboard = new Scanner(System.in);
- //printing LETTERGRADE and POINTRANGE
- System.out.println("Grading Scale:\n" +
- "A\t\t 90 - 100\n" +
- "B\t\t 80 - 89\n" +
- "C\t\t 70 - 79\n" +
- "D\t\t 60 - 69\n" +
- "F\t\t below 60");
- //declaring variables
- int finalOverallScore, totalKnownGradeWeight;
- double currentScore, avgToFinalLetterGrade;
- String input, letterGrade;
- System.out.print("What letter grade do you want to achieve for the course? ");
- String desiredGrade = keyboard.nextLine();
- //starting the if else statements
- if (desiredGrade.equals("A")) {
- finalOverallScore = 90;}
- else if (desiredGrade.equals("B")) {
- finalOverallScore = 80;}
- else if (desiredGrade.equals("C")) {
- finalOverallScore = 70;}
- else if(desiredGrade.equals("D")) {
- finalOverallScore = 50;}
- else if(desiredGrade.equals("F")) {
- finalOverallScore = 50;}
- else {
- System.out.println("Input Error");
- System.exit(0);
- }
- //entering the scores
- totalKnownGradeWeight = 0;
- //asking user to enter percentage weights
- System.out.print("Enter Percent Weights:\nExam 1:\t\t");
- exam1Weight = keyboard.nextInt();
- System.out.print("Exam 2:\t\t");
- exam2Weight = keyboard.nextInt();
- System.out.print("Final Exam:\t");
- finalExamWeight = keyboard.nextInt();
- System.out.print("Labs:\t\t");
- labWeight = keyboard.nextInt();
- System.out.print("Projects:\t");
- projectWeight = keyboard.nextInt();
- System.out.print("Attendance:\t");
- attendanceWeight = keyboard.nextInt();
- System.out.print("Quizzes:\t");
- quizWeight = keyboard.nextInt();
- int sumOfGradeWeights = (exam1Weight + exam2Weight + finalExamWeight + labWeight + projectWeight + attendanceWeight + quizWeight);
- if (sumOfGradeWeights > 100 || sumOfGradeWeights < 100) {
- System.out.print("Weights don’t add up to 100, program exiting...");
- System.exit(0);
- }
- else
- System.out.println("Enter your scores out of a 100:");
- //prompt to enter the score
- System.out.print("Do you know your Exam 1 score?");
- String studentInput;
- studentInput = keyboard.next();
- //if else statements for unknown exam 1 & 2 scores
- if (studentInput.equalsIgnoreCase("yes") || studentInput.equalsIgnoreCase("y")) {
- System.out.print("Score received on exam 1:");
- exam1Score = keyboard.nextInt();
- keyboard.next();
- totalKnownGradeWeight += exam1Weight;
- System.out.print("Do you know your Exam 2 score?");
- studentInput = keyboard.nextLine();
- if (studentInput.equalsIgnoreCase("yes") || studentInput.equalsIgnoreCase("y"))
- {
- System.out.print("Score received on final exam: ");
- finalExamScore = keyboard.nextInt();
- keyboard.next();
- totalKnownGradeWeight += finalExamWeight;
- }
- //using switch statements--
- //switch statements for project
- System.out.print("Do you know your project average? ");
- input = keyboard.next();
- switch (input)
- {
- case "yes":
- case "ye":
- case "y":
- System.out.print("Average Project Grade: ");
- projectScore = keyboard.nextInt();
- totalKnownGradeWeight += projectWeight;
- break;
- default:
- projectScore = 0;
- projectWeight = 0;
- break;
- }
- //switch statements for attendance
- System.out.print("Do you know your attendance average? ");
- input = keyboard.next();
- switch (input)
- {
- case "yes":
- case "ye":
- case "y":
- System.out.print("Average Attendance Grade: ");
- attendanceScore = keyboard.nextInt();
- totalKnownGradeWeight += attendanceWeight;
- break;
- default:
- attendanceScore = 0;
- attendanceWeight = 0;
- break;
- }
- //switch statements for quiz
- System.out.print("Do you know your quiz average? ");
- input = keyboard.next();
- switch (input)
- {
- case "yes":
- case "ye":
- case "y":
- System.out.print("Average Quiz Grade: ");
- quizScore = keyboard.nextInt();
- totalKnownGradeWeight += quizWeight;
- break;
- default:
- quizScore = 0;
- quizWeight = 0;
- break;
- }
- }
- //computing the scores
- double gradeScore;
- gradeScore = (exam1Weight * exam1Score) + (exam2Weight * exam2Score) + (finalExamWeight * finalExamScore) + (labWeight * labScore) + (projectWeight * projectScore) + (attendanceWeight * attendanceScore) + (quizWeight * quizScore);
- double gradeWeight;
- gradeWeight = totalKnownGradeWeight;
- double currentScore1;
- currentScore1 = (gradeScore/gradeWeight);
- System.out.printf("Current Score %5.2f" , currentScore1);
- //Converting current score to a letter grade
- String currentLetterGrade;
- if(currentScore >= 90)
- {
- currentLetterGrade = "A";
- }
- else if(currentScore1 >= 80)
- {
- currentLetterGrade = "B";
- }
- else if(currentScore1 >= 70)
- {
- currentLetterGrade = "C";
- }
- else if(currentScore1 >= 60)
- {
- currentLetterGrade = "D";
- }
- else
- {
- currentLetterGrade = "F";
- }
- System.out.println("Your current letter grade is a " + currentLetterGrade);
- //if else statements for outputs
- int gradeWanted;
- if(totalKnownGradeWeight == 100)
- {
- if(currentLetterGrade.equals(gradeWanted))
- System.out.println("Congratulations! You recieved the " + gradeWanted + " that you wanted!");
- else
- System.out.println("Sorry, you did not recieved the " + gradeWanted + " that you wanted.");
- System.exit(0);
- }
- //
- double avgFinalLetterGradeNumerator = (100 * finalOverallScore) - gradeScore;
- double abgFinalLetterGradeDenominator = (100 - totalKnownGradeWeight);
- double avgFinalLetterGradeDenominator;
- avgToFinalLetterGrade = (avgFinalLetterGradeNumerator/avgFinalLetterGradeDenominator);
- if(avgToFinalLetterGrade > 100)
- {
- System.out.println("Sorry, you cannot recieve a " + gradeWanted + " in the course");
- }
- else if(avgToFinalLetterGrade >= 0) {
- System.out.printf("You have to score an average greater than or equal to a %5.1f", avgToFinalLetterGrade);
- System.out.print(" in the remaining grade items to receieve a " + gradeWanted + " in the course");
- }
- else{
- System.out.println("You will recieve a " + gradeWanted + " no matter what");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement