jTruBela

Grade Calculator 1.0

Dec 14th, 2020 (edited)
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.76 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class gradesArray
  3. {
  4.     public static double ArraySum(double []Array) {
  5.         double sumArray = 0;
  6.         for (int i=0;i<Array.length; i++)
  7.         {
  8.             sumArray +=Array[i];
  9.         }
  10.         return sumArray;
  11.     }
  12.    
  13.     public static double MaxPoints(double []Array) {
  14.         double MAX = 100;
  15.         double totalPoints;
  16.  
  17.         totalPoints = Array.length*MAX;
  18.         return totalPoints;
  19.     }
  20.     public static void main(String[] args)
  21.     {
  22.         Scanner scan = new Scanner(System.in);
  23.        
  24.         //*********************************************************************
  25.         //  Enter the amount of grading categories used in grading
  26.         //          and create an array to store grading percentages
  27.         //*********************************************************************
  28.         System.out.println("Enter how many grade percentage "
  29.                 + "caterogies there are:");
  30.         int numCategories = scan.nextInt();
  31.         double [] gradePercentages = new double [numCategories];
  32.         double [] finalGrades = new double [numCategories];
  33.        
  34.         for (int i=0;i<numCategories;i++)
  35.         {
  36.             //**********************************************************************
  37.             //  Enter the data for category 1
  38.             //**********************************************************************
  39.             System.out.println("Enter the category name:");
  40.             String category = scan.next();
  41.             System.out.println("Enter category percentage:");
  42.             gradePercentages[i] = scan.nextInt();
  43.        
  44.                 //*********************************************************************
  45.                 // Determine how many assignments you took to calculate
  46.                 //      the average for that grade and create an array to
  47.                 //      store these assignment grades in
  48.                 //*********************************************************************
  49.                 System.out.println("For the "+ category +" category, enter the grades.");
  50.                 System.out.print("Enter number of grades: ");
  51.                 int numGrades = scan.nextInt();
  52.                 double categoryGrades[] = new double [numGrades];
  53.                 System.out.println("");
  54.        
  55.                 //*********************************************************************
  56.                 // For each assignment grade, add them to the array so
  57.                 //      that you may calculate them later
  58.                 //*********************************************************************
  59.                 for (int index=0;index<numGrades;index++)
  60.                 {
  61.                     System.out.println("Enter the grade for "
  62.                             + "assignment " + (index+1) + ":");
  63.                     categoryGrades[index] = scan.nextDouble();
  64.                 }
  65.                
  66.                     //*********************************************************************
  67.                     // Calculate the total number of points earned from
  68.                     //      each assignment, add them up, and get an average
  69.                     //      grade for that category
  70.                     //*********************************************************************
  71.                     System.out.println("Your total grade for " + category + " was " +
  72.                                 ArraySum(categoryGrades)
  73.                                 + "/"+ MaxPoints(categoryGrades));
  74.                
  75.                
  76.                     double grade = (ArraySum(categoryGrades) / //Divided by
  77.                                     (MaxPoints(categoryGrades)));
  78.        
  79.  
  80.                     finalGrades[i] = grade;
  81.  
  82.         }
  83.             for (int indexx=0;indexx<finalGrades.length;indexx++)
  84.             {
  85.                 finalGrades[indexx]=(finalGrades[indexx]*gradePercentages[indexx]);
  86.             }
  87.        
  88.        
  89.             //*********************************************************************
  90.             // Tell the user what grade they received in that category
  91.             //*********************************************************************
  92.             if (ArraySum(finalGrades) >= 93)
  93.             {
  94.                 System.out.println("You got an A with an average of " + ArraySum(finalGrades));
  95.             }
  96.             else
  97.             {
  98.                 System.out.println("You did not get an A. Your average was " + ArraySum(finalGrades));
  99.             }
  100.  
  101.             for (int grades = 0; grades < finalGrades.length; grades++)
  102.             {
  103.                 System.out.print(finalGrades[grades]+" ");
  104.             }
  105.  
  106.         scan.close();
  107.     }
  108. }
  109.  
Add Comment
Please, Sign In to add comment