Advertisement
Guest User

Untitled

a guest
Apr 27th, 2015
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.93 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. //Ben Feldman
  4. //This program calculates a student's course grade based on their homework and test grades.
  5. public class Gradanator {
  6.    public static void main(String[] args){
  7.       Scanner console = new Scanner(System.in);
  8.  
  9.       preamble();
  10.       gradeCalculator(console);
  11.    }
  12.  
  13.    //Prints the introduction message
  14.    public static void preamble(){
  15.       System.out.println("This program reads exam/homework scores");
  16.       System.out.println("and reports your overall course grade.");
  17.       System.out.println();
  18.    }
  19.  
  20.    //Calculates your final % grade in the class and a rough estimate of your grade on the 4.0 scale based on user input
  21.    public static void gradeCalculator(Scanner console){
  22.       double finalGrade = Math.round(10.0 * (test("Midterm", console) + test("Final", console) + homework(console))) / 10.0;
  23.       System.out.println("Overall percentage = " + finalGrade);
  24.       System.out.print("Your grade will be at least: ");
  25.       if (finalGrade >= 100.0){
  26.          System.out.println("4.0");
  27.          System.out.println("A winner is you!");
  28.       }
  29.       else if (finalGrade >= 85.0){
  30.          System.out.println("3.0");
  31.          System.out.println("Good work! Nice shootin' Tex! You did it!");
  32.       }
  33.       else if (finalGrade >= 75.0){
  34.          System.out.println("2.0");
  35.          System.out.println("Good job, you're probably above average!");
  36.       }
  37.       else if (finalGrade >= 60.0){
  38.          System.out.println("0.7");
  39.          System.out.println("Hey, chin up, you could still pass. Maybe.");
  40.       }
  41.       else if (finalGrade < 60.0){
  42.          System.out.println("0.0");
  43.          System.out.println("That is certainly... unfortunate.");
  44.       }
  45.    }
  46.  
  47.    //Calculates the weighted score of a test of variable name based on user input
  48.    public static double test(String testName, Scanner console){
  49.       System.out.println(testName + ":");
  50.       System.out.print("Weight (0-100)? ");
  51.       int weight = console.nextInt();
  52.       System.out.print("Score earned? ");
  53.       int scoreRaw = console.nextInt();
  54.       int scoreShifted = scoreRaw + shift(console);
  55.       //Resets impossibly high grades to 100
  56.       if (scoreShifted > 100){
  57.          scoreShifted = 100;
  58.       }
  59.       //Resets negative grades to 0
  60.       else if (scoreShifted < 0){
  61.          scoreShifted = 0;
  62.       }
  63.       System.out.println("Total points = " + scoreShifted + " / 100");
  64.       double scoreWeighted = scoreShifted * (weight/100.0);
  65.       System.out.println("Weighted score = " + Math.round(scoreWeighted*10.0)/10.0 + " / " + weight);
  66.       System.out.println();
  67.       return scoreWeighted;
  68.    }
  69.  
  70.    //Calculates the grade shift of a test, if present, based on user input
  71.    public static int shift(Scanner console){
  72.       System.out.print("Were scores shifted (1=yes, 2=no)? ");
  73.       int isShift = console.nextInt();
  74.       int shiftAmount;
  75.       if (isShift == 1){
  76.          System.out.print("Shift amount? ");
  77.          shiftAmount = console.nextInt();
  78.       }
  79.       else if (isShift == 2){
  80.          shiftAmount = 0;
  81.       }
  82.       //This section accounts for users not following instructions
  83.       else{
  84.          System.out.println("Error: Please type 1 or 2.");
  85.          shiftAmount = shift(console);
  86.       }      
  87.       return shiftAmount;
  88.    }
  89.  
  90.    //Calculates the weighted score of your homework and your quiz section attendance based on user input
  91.    public static double homework(Scanner console){
  92.       System.out.println("Homework:");
  93.       System.out.print("Weight (0-100)? ");
  94.       int weight = console.nextInt();
  95.       int scoreEarned = 0;
  96.       int scorePossible = 0;
  97.       System.out.print("Number of assignments? ");
  98.       int numberOfAssignments = console.nextInt();
  99.       for(int count = 1; count <= numberOfAssignments; count++){
  100.          System.out.print("Assignment " + count + " score and max? ");
  101.          scoreEarned = scoreEarned + console.nextInt();
  102.          scorePossible = scorePossible + console.nextInt();
  103.       }
  104.       System.out.print("How many sections did you attend? ");
  105.       int sectionPoints = 5*console.nextInt();
  106.       //If the student attends more than 6 sections, this section ensures they only receive the maximum 30 points
  107.       if(sectionPoints > 30){
  108.         sectionPoints = 30;
  109.       }
  110.       int scoreTotal = scoreEarned + sectionPoints;
  111.       //If the student scores over the maximum score, this resets the score to whatever the maximum score is
  112.       if(scoreTotal > scorePossible + 30){
  113.          scoreTotal = scorePossible + 30;
  114.       }
  115.       System.out.println("Section points = " + sectionPoints + " / 30");
  116.       System.out.println("Total points = " + (scoreTotal) + " / " + (scorePossible + 30));
  117.       double scoreWeighted = (scoreTotal) * weight / (scorePossible + 30.0);
  118.       System.out.println("Weighted score = " + Math.round(scoreWeighted*10.0)/10.0 + " / " + weight);
  119.       System.out.println();
  120.       return scoreWeighted;
  121.    }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement