Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Program {
- public static void main(String[] args)
- {
- /*
- * Nick Taylor
- * Philip Lempke
- * Mariano Gonzalez
- * Not Neal 'no-show' McMahon
- *
- * Our program prompts the user to enter a list of grades so that they can calculate_
- * the sum of grades, the averages of each grade, min/max grade, and possible extra credit_
- * It will then print you off a summary of this information_
- * In doing this we learned how to create multiple comments with "/*" instead of "//"
- * how to use an "if" statement in a println in order to add an additional option to the statement
- * how to take an arbitrary amount of numbers/inputs from a user and calculate results from them
- * how to use a screen sharing application other than adobe connect so that we can work together_
- * remotely from our respective homes
- *
- *
- * Variables
- * Initialize
- * Request input
- * Divide the input by grade, counters and sums go up
- * determine if input is lower/greater than min/max and change min/max accordingly
- * calculate averages of individual grades and total
- * calculate sums of individual grades and total
- * Output
- */
- // TODO Auto-generated method stub
- Scanner keyboard = new Scanner(System.in);
- //Declare the variables
- int gradeA, gradeB, gradeC, gradeD, gradeF;
- double sumA, sumB, sumC, sumD, sumF;
- double minGrade = 1000;
- double maxGrade = 0;
- double sum;
- double averageGrade;
- int counter;
- int extraCreditCounter;
- //initialize the variables
- sum = 0;
- counter = 0;
- gradeA = 0;
- gradeB = 0;
- gradeC = 0;
- gradeD = 0;
- gradeF = 0;
- sumA = 0;
- sumB = 0;
- sumC = 0;
- sumD = 0;
- sumF = 0;
- extraCreditCounter = 0;
- //prompt the user for the grades they'd like to input
- System.out.println("Please enter the list of scores from 0 to 100: ");
- System.out.println("Please enter a negative number to stop entering grades");
- int gradeInputed = keyboard.nextInt();
- // establish conditions for each respective grade as well as adding up
- // the sums of each grade
- while (gradeInputed >=0)
- {
- counter++;
- sum += gradeInputed;
- if (gradeInputed >= 90)
- {
- gradeA++;
- sumA += gradeInputed;
- if (gradeInputed > 100)
- {
- extraCreditCounter++;
- }
- }
- else if(gradeInputed >= 80 && gradeInputed <=89)
- {
- gradeB++;
- sumB += gradeInputed;
- }
- else if(gradeInputed >= 70 && gradeInputed <=79)
- {
- gradeC++;
- sumC += gradeInputed;
- }
- else if(gradeInputed >= 60 && gradeInputed <=69)
- {
- gradeD++;
- sumD += gradeInputed;
- }
- else if(gradeInputed >= 0 && gradeInputed <=59)
- {
- gradeF++;
- sumF += gradeInputed;
- }
- else if(gradeInputed < 0)
- System.out.println("You have entered an invalid grade. Please try again.");
- if (gradeInputed > maxGrade)
- {
- maxGrade = gradeInputed;
- }
- if (gradeInputed < minGrade)
- {
- minGrade = gradeInputed;
- }
- gradeInputed = keyboard.nextInt();
- }
- // create a condition for the average grade
- averageGrade = sum / counter;
- if (sumA >0)
- {
- sumA = sumA / gradeA;
- }
- if (sumB >0)
- {
- sumB = sumB / gradeB;
- }
- if (sumC >0)
- {
- sumC = sumC / gradeC;
- }
- if (sumD >0)
- {
- sumD = sumD / gradeD;
- }
- if (sumF >0)
- {
- sumF = sumF / gradeF;
- }
- // Print out the report for all of the grades the user entered
- System.out.println("The sum of scores is: " +sum);
- System.out.println();
- System.out.println("The total number of scores: " + counter);
- System.out.print("The total number of A's: " + gradeA);
- if (extraCreditCounter > 0)
- {
- System.out.println(" with " + extraCreditCounter + " receiving extra credit!");
- }
- else
- {
- System.out.println();
- }
- System.out.println("The total number of B's: " + gradeB);
- System.out.println("The total number of C's: " + gradeC);
- System.out.println("The total number of D's: " + gradeD);
- System.out.println("The total number of F's: " + gradeF);
- System.out.println();
- System.out.println("The average grade is: " + averageGrade);
- System.out.println("The average A is: " + sumA);
- System.out.println("The average B is: " + sumB);
- System.out.println("The average C is: " + sumC);
- System.out.println("The average D is: " + sumD);
- System.out.println("The average F is: " + sumF);
- System.out.println();
- System.out.println("The highest grade is: " + maxGrade);
- System.out.println("The lowest grade is: " + minGrade);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement