Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- //Ben Feldman
- //This program calculates a student's course grade based on their homework and test grades.
- public class Gradanator {
- public static void main(String[] args){
- Scanner console = new Scanner(System.in);
- preamble();
- gradeCalculator(console);
- }
- //Prints the introduction message
- public static void preamble(){
- System.out.println("This program reads exam/homework scores");
- System.out.println("and reports your overall course grade.");
- System.out.println();
- }
- //Calculates your final % grade in the class and a rough estimate of your grade on the 4.0 scale based on user input
- public static void gradeCalculator(Scanner console){
- double finalGrade = Math.round(10.0 * (test("Midterm", console) + test("Final", console) + homework(console))) / 10.0;
- System.out.println("Overall percentage = " + finalGrade);
- System.out.print("Your grade will be at least: ");
- if (finalGrade >= 100.0){
- System.out.println("4.0");
- System.out.println("A winner is you!");
- }
- else if (finalGrade >= 85.0){
- System.out.println("3.0");
- System.out.println("Good work! Nice shootin' Tex! You did it!");
- }
- else if (finalGrade >= 75.0){
- System.out.println("2.0");
- System.out.println("Good job, you're probably above average!");
- }
- else if (finalGrade >= 60.0){
- System.out.println("0.7");
- System.out.println("Hey, chin up, you could still pass. Maybe.");
- }
- else if (finalGrade < 60.0){
- System.out.println("0.0");
- System.out.println("That is certainly... unfortunate.");
- }
- }
- //Calculates the weighted score of a test of variable name based on user input
- public static double test(String testName, Scanner console){
- System.out.println(testName + ":");
- System.out.print("Weight (0-100)? ");
- int weight = console.nextInt();
- System.out.print("Score earned? ");
- int scoreRaw = console.nextInt();
- int scoreShifted = scoreRaw + shift(console);
- //Resets impossibly high grades to 100
- if (scoreShifted > 100){
- scoreShifted = 100;
- }
- //Resets negative grades to 0
- else if (scoreShifted < 0){
- scoreShifted = 0;
- }
- System.out.println("Total points = " + scoreShifted + " / 100");
- double scoreWeighted = scoreShifted * (weight/100.0);
- System.out.println("Weighted score = " + Math.round(scoreWeighted*10.0)/10.0 + " / " + weight);
- System.out.println();
- return scoreWeighted;
- }
- //Calculates the grade shift of a test, if present, based on user input
- public static int shift(Scanner console){
- System.out.print("Were scores shifted (1=yes, 2=no)? ");
- int isShift = console.nextInt();
- int shiftAmount;
- if (isShift == 1){
- System.out.print("Shift amount? ");
- shiftAmount = console.nextInt();
- }
- else if (isShift == 2){
- shiftAmount = 0;
- }
- //This section accounts for users not following instructions
- else{
- System.out.println("Error: Please type 1 or 2.");
- shiftAmount = shift(console);
- }
- return shiftAmount;
- }
- //Calculates the weighted score of your homework and your quiz section attendance based on user input
- public static double homework(Scanner console){
- System.out.println("Homework:");
- System.out.print("Weight (0-100)? ");
- int weight = console.nextInt();
- int scoreEarned = 0;
- int scorePossible = 0;
- System.out.print("Number of assignments? ");
- int numberOfAssignments = console.nextInt();
- for(int count = 1; count <= numberOfAssignments; count++){
- System.out.print("Assignment " + count + " score and max? ");
- scoreEarned = scoreEarned + console.nextInt();
- scorePossible = scorePossible + console.nextInt();
- }
- System.out.print("How many sections did you attend? ");
- int sectionPoints = 5*console.nextInt();
- //If the student attends more than 6 sections, this section ensures they only receive the maximum 30 points
- if(sectionPoints > 30){
- sectionPoints = 30;
- }
- int scoreTotal = scoreEarned + sectionPoints;
- //If the student scores over the maximum score, this resets the score to whatever the maximum score is
- if(scoreTotal > scorePossible + 30){
- scoreTotal = scorePossible + 30;
- }
- System.out.println("Section points = " + sectionPoints + " / 30");
- System.out.println("Total points = " + (scoreTotal) + " / " + (scorePossible + 30));
- double scoreWeighted = (scoreTotal) * weight / (scorePossible + 30.0);
- System.out.println("Weighted score = " + Math.round(scoreWeighted*10.0)/10.0 + " / " + weight);
- System.out.println();
- return scoreWeighted;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement