Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

CSCE 155A Spring 2018 Homework Assignment 3: Gradebook II Assigned: Monday, Febr

ID: 3723651 • Letter: C

Question

CSCE 155A Spring 2018

Homework Assignment 3: Gradebook II

Assigned: Monday, February 19, 2018

Due: Monday, March 5, 2018

Note: This assignment is to be completed individually - collaboration is strictly prohibited. Points:100 points

The objectives of this homework assignment:

         1. Master conditional and looping logic flow in Java.

         2. Familiarize with the use of arrays

                  a. Manipulate a collection of data values using an array                             b. Compute statistics out of an array of values                   c. Declare and use an array of primitive data types

         3. Familiarize with the use of exception handling for data format and range checking

         4. Master code documentation, compilation, and execution

     5. Expose to Java syntax, programming styles, and a Java class.

Draw a flowchart for the algorithm and write a program that processes the statistics for grades for a group of students in the CSCE155A class. In order to do this, you need to store this information in a Java two-dimensional array of values representing points earned in the class. Dimension 1 represents the students and dimension 2 represents the categories of points, which is as follows:

Homework Assignments (25%) – 600 points possible [6 assignments x 100 points each]

Labs (25%) – 600 points possible [15 labs x 40 points each]

Midterms (25%) – 600 points possible [2 exams x 300 points each]

PRS Test (4.17%) – 100 points possible

Extra Credit (10.42%) – 250 points possible

Final Exam (20.83%) – 500 points possible You will randomly generate the points for each category according to its maximum possible points. Your program will first take in an integer as input, which will be the seed to your random number generator. Then you would simply need to inquire from the user number of students in the class. Your program will use this information to randomly generate the points and fill the array. Note: You cannot use JCF classes or any standard classes to store the data values.

The grading scale for this course is as followed:

• A+ >= 96.67%

•A    >= 91.71%

• A- >= 90.04%

• B+ >= 86.71%

•B   >= 81.71%

• B- >= 80.04%

• C+ >= 76.71%

• C >= 71.71%

• C- >= 70.04%

• D+ >= 66.71%

• D >= 61.71%

• D- >= 60.04%

• F < 60.03%

You are given the following set of minimum requirements to design and implement the overall grade processing application that stores the points in each category for each specific student.

Grade values should be a random integer between one half of the maximum grade in the category and the maximum grade in the category (e.g. in “Assignments”, the value should be a random integer between 300 and 600, inclusively).

Program should be able to accept at least two (2) students and up to one hundred (100) students.

Program should properly handle any exceptions that could be thrown during the processing of user input/entry.

For the seed to work correctly for the example below and for the Webgrader, you need to use the Random class in Java. Create an instance of this standard class with the inputted seed value and use its appropriate methods to generate your random numbers to fill your array.

Need to be able to nicely print the table of information. This information needs to be stored in a Java two-dimensional array with individual grade elements for each student in each category. Note: You cannot use JCF classes or any standard classes to store the data values. You are also expected to properly handle any exceptions that could be thrown during the processing of your array.

Need to print the total points, percentage, and letter grade earned by each student. The percentage needs to be rounded to two decimal places.

Need to print the students having made the most and least points over all categories combined (e.g. student with the highest grade and student with the lowest grade).

Need to print the average, maximum, minimum, and total points earned in each category. Average should be rounded to and displayed as two decimal places.

Program should repeat by allowing the user to enter in another number of students.

Explanation / Answer

import java.util.*;

class Main {
   /**
   * Calculates Grade
   * @param marks : Marks Obtained
   * @param maxMarks: Maximum Marks That can be Obtained
   * @return: String of Grade
   */
   public static String calculateGrade(double marks, double maxMarks){
       double percentage = (marks*100)/maxMarks;
       if (percentage >= 96.67){
           return "A+";
       } else if (percentage >= 91.71){
           return "A";
       } else if (percentage >= 90.04){
           return "A-";
       } else if (percentage >= 86.71){
           return "B+";
       } else if (percentage >= 81.71){
           return "B";
       } else if (percentage >= 80.04){
           return "B-";
       } else if (percentage >= 76.71){
           return "C+";
       } else if (percentage >= 71.71){
           return "C";
       } else if (percentage >= 70.04){
           return "C-";
       } else if (percentage >= 66.71){
           return "D+";
       } else if (percentage >= 61.71){
           return "D";
       } else if (percentage >= 60.04){
           return "D-";
       }
       return "F";
   }
  
    public static void main(String args[]) {
      
       // Number of Times the code should repeat i.e. number of time you can input number of students
       int numTimesCodeRepeats = 3;
      
       Scanner sc= new Scanner(System.in);
       long seedValue; // Seed Value for random Number generator
       try {
           System.out.print("Enter Seed Value : ");
           seedValue = sc.nextLong();
       } catch(Exception e){
           System.out.println("Exception :"+e.toString());
           sc.close();
           return;
       }
      
       // Random Number generator
       Random randValGen = new Random(seedValue);

       for (int loop = 0; loop < numTimesCodeRepeats; loop++) {
          
           int numStudents;// Number of Students
          
           System.out.print("Enter Number of Students (2 - 100): ");
           try {
               numStudents = sc.nextInt();
           } catch(Exception e){ // Exception in input
               System.out.println("Exception : "+e.toString());
               sc.close();
               return;
           }
           // Number of Students Should be in range
           if (numStudents < 2 || numStudents > 100){
               System.out.println("Number of Students Out of range !!");
               System.out.println();
               continue;
           }
          
          
           int maxMarksArr[] = {600, 600, 600, 100, 250, 500}; // max marks in each category
          
           int numAssignments = maxMarksArr.length; // Number of assignments
           int maxMarks = 0; // Overall Max Marks that can be achieved
           for (int i = 0; i < numAssignments; i++) {
               maxMarks += maxMarksArr[i];
           }
          
                  
           int arr[][] = new int[numStudents][numAssignments]; //Array of marks of all Student
           String grades[][] = new String[numAssignments][numAssignments]; // Grade of each student in each Category
          
           System.out.println();
           System.out.println("Marks Array : "); // Print the marks Array of Students
           for (int i = 0; i < numStudents; i++) {
               for (int j = 0; j < numAssignments; j++) {
                   int marks = maxMarksArr[j]; // Maximum Marks in this category
                   int halfMarks = marks/2; // maximum Marks /2
                  
                   // Random Number Range: [0, half] + half = [half , Max Marks]
                   arr[i][j] = randValGen.nextInt(1 + halfMarks) + halfMarks;
                   System.out.print(arr[i][j]+" ");
               }
               System.out.println();
           }
           System.out.println();
          
           // Calculate Grade
           for (int i = 0; i < numStudents; i++) {
               for (int j = 0; j < numAssignments; j++) {
                   grades[i][j] = calculateGrade(arr[i][j], maxMarksArr[j]);
               }
           }
          

           int maxStudentMarks = 0; // Maximum Overall Marks of any Student
           int minStudentMarks = maxMarks; // Lowest Overall Marks Obtained By Any Student
          
           for (int i = 0; i < numStudents; i++) {
               System.out.println("Student "+(i+1)); // Student Id
               System.out.print("Marks : ");
               int sumMarks = 0; // Total Marks of each Student
               for (int j = 0; j < grades.length; j++) {
                   System.out.print(arr[i][j]+" "); // Marks in each Category
                   sumMarks += arr[i][j];
               }
               System.out.println();
               System.out.print("Grade in Each Category: "); // Print Grades
               for (int j = 0; j < grades.length; j++) {
                   System.out.print(grades[i][j]+" ");
               }
               System.out.println();
              
               double percentage = (sumMarks*100)/((double)maxMarks); // Percentage of Marks
               System.out.println("Total Points: "+sumMarks);
               System.out.printf("Percentage : %.2f ", percentage);
               System.out.println("Overall Grade : "+calculateGrade(sumMarks, maxMarks)); // Overall Grades across All Category
              
               System.out.println();
              
              
               if (maxStudentMarks < sumMarks ){ // to find Max Marks
                   maxStudentMarks = sumMarks;
               }
               if (minStudentMarks > sumMarks){ // to find Minimum Marks
                   minStudentMarks = sumMarks;
               }
           }
           System.out.println();
           for (int j = 0; j < numAssignments; j++) {
               // Finds Average, Max , MIn, total marks in each Category
               double sumCategoryMarks = 0; // Total Points in jth category
               int maxCategoryMarks = 0; // Maximum Points in jth category
               int minCategoryMarks = Integer.MAX_VALUE; // minimum Points in in jth category
               for (int i = 0; i < numStudents; i++) {
                   sumCategoryMarks += arr[i][j];
                   if (arr[i][j] < minCategoryMarks){
                       minCategoryMarks = arr[i][j];
                   }
                   if (arr[i][j] > maxCategoryMarks){
                       maxCategoryMarks = arr[i][j];
                   }
               }
               // Print Output
               double avgCategoryMarks = sumCategoryMarks/numStudents; // Average pints in jth category
               System.out.println("Category : "+(j+1));
               System.out.println("Max Marks: "+maxCategoryMarks);
               System.out.println("Min Marks: "+minCategoryMarks);
               System.out.println("Total Marks: "+sumCategoryMarks);
               System.out.printf("Average Marks: %.2f ",avgCategoryMarks);
              
               System.out.println();
           }
           System.out.println();
       }
       sc.close();
    }
}


*************************************

Note: Currently a user can enter number of Students 3 times, this can be Changed using variable named "numTimesCodeRepeats" in beginning of Main Class.

*********************************************

Sample Input Output:

Enter Seed Value : 7
Enter Number of Students (2 - 100): 3

Marks Array :
366 319 437 93 207 279
347 454 563 53 209 310
317 591 493 93 230 386

Student 1
Marks : 366 319 437 93 207 279
Grade in Each Category: D- F C A B F
Total Points: 1701
Percentage : 64.19
Overall Grade : D

Student 2
Marks : 347 454 563 53 209 310
Grade in Each Category: F C A F B D
Total Points: 1936
Percentage : 73.06
Overall Grade : C

Student 3
Marks : 317 591 493 93 230 386
Grade in Each Category: F A+ B A A C+
Total Points: 2110
Percentage : 79.62
Overall Grade : C+


Category : 1
Max Marks: 366
Min Marks: 317
Total Marks: 1030.0
Average Marks: 343.33

Category : 2
Max Marks: 591
Min Marks: 319
Total Marks: 1364.0
Average Marks: 454.67

Category : 3
Max Marks: 563
Min Marks: 437
Total Marks: 1493.0
Average Marks: 497.67

Category : 4
Max Marks: 93
Min Marks: 53
Total Marks: 239.0
Average Marks: 79.67

Category : 5
Max Marks: 230
Min Marks: 207
Total Marks: 646.0
Average Marks: 215.33

Category : 6
Max Marks: 386
Min Marks: 279
Total Marks: 975.0
Average Marks: 325.00


Enter Number of Students (2 - 100): 200
Number of Students Out of range !!

Enter Number of Students (2 - 100): string
Exception : java.util.InputMismatchException