Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class gradesArray
- {
- public static double ArraySum(double []Array) {
- double sumArray = 0;
- for (int i=0;i<Array.length; i++)
- {
- sumArray +=Array[i];
- }
- return sumArray;
- }
- public static double MaxPoints(double []Array) {
- double MAX = 100;
- double totalPoints;
- totalPoints = Array.length*MAX;
- return totalPoints;
- }
- public static void main(String[] args)
- {
- Scanner scan = new Scanner(System.in);
- //*********************************************************************
- // Enter the amount of grading categories used in grading
- // and create an array to store grading percentages
- //*********************************************************************
- System.out.println("Enter how many grade percentage "
- + "caterogies there are:");
- int numCategories = scan.nextInt();
- double [] gradePercentages = new double [numCategories];
- double [] finalGrades = new double [numCategories];
- for (int i=0;i<numCategories;i++)
- {
- //**********************************************************************
- // Enter the data for category 1
- //**********************************************************************
- System.out.println("Enter the category name:");
- String category = scan.next();
- System.out.println("Enter category percentage:");
- gradePercentages[i] = scan.nextInt();
- //*********************************************************************
- // Determine how many assignments you took to calculate
- // the average for that grade and create an array to
- // store these assignment grades in
- //*********************************************************************
- System.out.println("For the "+ category +" category, enter the grades.");
- System.out.print("Enter number of grades: ");
- int numGrades = scan.nextInt();
- double categoryGrades[] = new double [numGrades];
- System.out.println("");
- //*********************************************************************
- // For each assignment grade, add them to the array so
- // that you may calculate them later
- //*********************************************************************
- for (int index=0;index<numGrades;index++)
- {
- System.out.println("Enter the grade for "
- + "assignment " + (index+1) + ":");
- categoryGrades[index] = scan.nextDouble();
- }
- //*********************************************************************
- // Calculate the total number of points earned from
- // each assignment, add them up, and get an average
- // grade for that category
- //*********************************************************************
- System.out.println("Your total grade for " + category + " was " +
- ArraySum(categoryGrades)
- + "/"+ MaxPoints(categoryGrades));
- double grade = (ArraySum(categoryGrades) / //Divided by
- (MaxPoints(categoryGrades)));
- finalGrades[i] = grade;
- }
- for (int indexx=0;indexx<finalGrades.length;indexx++)
- {
- finalGrades[indexx]=(finalGrades[indexx]*gradePercentages[indexx]);
- }
- //*********************************************************************
- // Tell the user what grade they received in that category
- //*********************************************************************
- if (ArraySum(finalGrades) >= 93)
- {
- System.out.println("You got an A with an average of " + ArraySum(finalGrades));
- }
- else
- {
- System.out.println("You did not get an A. Your average was " + ArraySum(finalGrades));
- }
- for (int grades = 0; grades < finalGrades.length; grades++)
- {
- System.out.print(finalGrades[grades]+" ");
- }
- scan.close();
- }
- }
Add Comment
Please, Sign In to add comment