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

Class Grading Simulation: we will be simulating test scores and homework scores

ID: 3822478 • Letter: C

Question

Class Grading Simulation: we will be simulating test scores and homework scores for students, curving the individual test scores, determining if we need to offer extra credit, and reporting final averages for all students.


(15 points) We will be simulating students by using three arrays for 100 students.
o The first array holds their name (1 per student)
o The second array will hold their homework scores (6 per student)
o The third array will hold their test scores (3 per student)


(15 points) Initialize the Arrays using the following instructions:
o The name array should be initialized using random first names and random last names in the format LastName, FirstName (like we did in class)
o The homework score array should be initialized using random integers between 60 and 100 for each student
o The test score array should be initialized using random numbers between 60 and 100


(30 points) For each exam, determine if there needs to be a curve and do something about it if necessary.
o A curve is necessary if the average of the scores for that test is below 75. If a curve is necessary, add the curve to the test scores and report the curve (if no curve, necessary report that as well)


(20 points) Determine if there needs to be homework extra-credit offered.
o Extra credit is necessary if and only if the average of all non-zero homeworks for all students is less than 75
o If extra-credit is necessary, determine how much (75-average)*2 and offer it. You should assume that only some people will do it, so add to everyone’s last homework a random amount of extra credit between 0 and (75-average)*2.
o If extra-credit was necessary, report how much was offered, otherwise report none was necessary.


(20 points) Report the results of the simulated class!
o Calculate the final grade for each student using the grading of this class (15% for test1, 25% for test2, 30% for test3) and 30% for the homework average
o Report the final score for each student on its own line similar to: LastName, FirstName: SCORE
o Print a blank line and then report the frequency (percentage using %) of each final grade in the class. Hint: Determine how many of each grade and divide that by the number of grades (100) and then multiply by a 100 (percentage).

Explanation / Answer

PROGRAM CODE:

package com;

import java.util.Random;

public class ClassSimulation {

static String firstNames[] = {"James", "Peter", "Mike", "Alicia", "Leena", "Divya", "Sherlock", "Miranda", "Julio", "Dilan"};
static String lastNames[] = {"Holland", "Reynolds", "Sharma", "Holmes", "Rayland", "Watson", "Lee", "Ray", "Lolly", "Sprouse"};
  
public static void main(String[] args) {
  
Random random = new Random();
String names[] = new String[100];
int homeworkScores[][] = new int[100][6];
int eScores[][] = new int[100][3];
double homeAvg = 0;
int e1HighestScore = 0;
int e2HighestScore = 0;
int e3HighestScore = 0;
int e1Curve, e2Curve, e3Curve;
double e1Avg = 0.0;
double e2Avg = 0.0;
double e3Avg = 0.0;
  
double finalScores[] = new double[100];
int frequency[] = new int[100];
int scoreCounter = 0;
//Initializing all the arrays
for(int i=0; i<100; i++)
{
names[i] = lastNames[random.nextInt(10)] + ", " + firstNames[random.nextInt(10)];
for(int j=0; j<6; j++)
homeworkScores[i][j] = random.nextInt(41) + 60;
for(int j=0; j<3; j++)
eScores[i][j] = random.nextInt(41) + 60;
}
  
//Determining curve for each e
//e 1 - determining the highest score
e1HighestScore = eScores[0][0];
for(int i=0; i<100; i++)
{
e1Avg += eScores[i][0];
if(e1HighestScore<eScores[i][0])
e1HighestScore = eScores[i][0];
}
e1Avg = e1Avg/100.0;
  
if(e1Avg <75)
{
  
e1Curve = 100 - e1HighestScore;
System.out.println("Curve of " + e1Curve + " was added for e 1");
for(int i=0; i<100; i++)
{
eScores[i][0] += e1Curve;
}
}
  
//e 1 - determining the highest score
e2HighestScore = eScores[0][1];
for(int i=0; i<100; i++)
{
e2Avg += eScores[i][1];
if(e2HighestScore<eScores[i][1])
e2HighestScore = eScores[i][1];
}
e2Avg = e2Avg/100.0;
  
if(e2Avg <75)
{
e2Curve = 100 - e2HighestScore;
System.out.println("Curve of " + e2Curve + " was added for e 1");
for(int i=0; i<100; i++)
{
eScores[i][1] += e2Curve;
}
}
  
//e 1 - determining the highest score
e3HighestScore = eScores[0][2];
for(int i=0; i<100; i++)
{
e3Avg += eScores[i][2];
if(e3HighestScore<eScores[i][2])
e3HighestScore = eScores[i][2];
}
e3Avg = e3Avg/100.0;
  
if(e3Avg <75)
{
e3Curve = 100 - e3HighestScore;
System.out.println("Curve of " + e3Curve + " was added for e 1");
for(int i=0; i<100; i++)
{
eScores[i][2] += e3Curve;
}
}
  
//determining the average for homeworks
for(int i=0; i<100; i++)
{
homeAvg += homeworkScores[i][0];
homeAvg += homeworkScores[i][1];
homeAvg += homeworkScores[i][2];
homeAvg += homeworkScores[i][3];
homeAvg += homeworkScores[i][4];
homeAvg += homeworkScores[i][5];
}
homeAvg = homeAvg/600.0;
  
if(homeAvg<75)
{
  
for(int i=0; i<100; i++)
{
int extraCredit = (75 - (int)homeAvg)*2;
System.out.println("An extra credit of " + extraCredit + " was added for " + names[i]);
homeworkScores[i][5] += random.nextInt();
}
}
  
for(int i=0; i<100; i++)
{
double score = (eScores[i][0]*15)/100.0 + (eScores[i][1]*25)/100.0 +(eScores[i][2]*30)/100.0;
double homeAverage = homeworkScores[i][0] + homeworkScores[i][1] + homeworkScores[i][2] + homeworkScores[i][3] + homeworkScores[i][4] + homeworkScores[i][5];
homeAverage = homeAverage/6;
score += homeAverage*30/100.0;
score = Math.round(score);
boolean isFound = false;
int scoreIndex = 0;
for(int j=0; j<scoreCounter; j++)
{
   if(finalScores[j] == score)
   {
       frequency[j]++;
       isFound = true;
       scoreIndex = j;
       break;
   }
}
if(!isFound)
{
   finalScores[scoreCounter] = score;
   frequency[scoreCounter] = 1;
   scoreIndex = scoreCounter;
   scoreCounter++;
}
System.out.println(names[i] + ": " + score);
System.out.println(" Frequency of " + score + " is " + frequency[scoreIndex] + " -----------------------------------");
}
}

}

OUTPUT:

Holland, Alicia: 77.0

Frequency of 77.0 is 1
-----------------------------------
Rayland, Divya: 76.0

Frequency of 76.0 is 1
-----------------------------------
Lolly, Divya: 85.0

Frequency of 85.0 is 1
-----------------------------------
Ray, Miranda: 74.0

Frequency of 74.0 is 1
-----------------------------------
Lee, Alicia: 80.0

Frequency of 80.0 is 1
-----------------------------------
Holland, Julio: 84.0

Frequency of 84.0 is 1
-----------------------------------
Holland, Alicia: 91.0

Frequency of 91.0 is 1
-----------------------------------
Reynolds, Peter: 77.0

Frequency of 77.0 is 2
-----------------------------------
Lee, Mike: 77.0

Frequency of 77.0 is 3
-----------------------------------
Holland, Mike: 80.0

Frequency of 80.0 is 2
-----------------------------------
Holland, Leena: 89.0

Frequency of 89.0 is 1
-----------------------------------
Lolly, Alicia: 72.0

Frequency of 72.0 is 1
-----------------------------------
Sharma, Leena: 75.0

Frequency of 75.0 is 1
-----------------------------------
Ray, Peter: 89.0

Frequency of 89.0 is 2
-----------------------------------
Sprouse, Alicia: 75.0

Frequency of 75.0 is 2
-----------------------------------
Sharma, Peter: 81.0

Frequency of 81.0 is 1
-----------------------------------
Holland, Sherlock: 74.0

Frequency of 74.0 is 2
-----------------------------------
Sharma, Divya: 65.0

Frequency of 65.0 is 1
-----------------------------------
Lee, Sherlock: 74.0

Frequency of 74.0 is 3
-----------------------------------
Watson, Sherlock: 78.0

Frequency of 78.0 is 1
-----------------------------------
Lee, Divya: 75.0

Frequency of 75.0 is 3
-----------------------------------
Lee, Sherlock: 72.0

Frequency of 72.0 is 2
-----------------------------------
Sharma, James: 77.0

Frequency of 77.0 is 4
-----------------------------------
Lolly, Peter: 85.0

Frequency of 85.0 is 2
-----------------------------------
Holland, James: 86.0

Frequency of 86.0 is 1
-----------------------------------
Ray, Leena: 81.0

Frequency of 81.0 is 2
-----------------------------------
Rayland, Divya: 90.0

Frequency of 90.0 is 1
-----------------------------------
Reynolds, Divya: 78.0

Frequency of 78.0 is 2
-----------------------------------
Holmes, Julio: 78.0

Frequency of 78.0 is 3
-----------------------------------
Lolly, Sherlock: 84.0

Frequency of 84.0 is 2
-----------------------------------
Sprouse, James: 77.0

Frequency of 77.0 is 5
-----------------------------------
Sharma, Sherlock: 82.0

Frequency of 82.0 is 1
-----------------------------------
Holmes, Mike: 78.0

Frequency of 78.0 is 4
-----------------------------------
Holmes, Alicia: 73.0

Frequency of 73.0 is 1
-----------------------------------
Lee, Julio: 81.0

Frequency of 81.0 is 3
-----------------------------------
Lee, Peter: 78.0

Frequency of 78.0 is 5
-----------------------------------
Lolly, Leena: 80.0

Frequency of 80.0 is 3
-----------------------------------
Lee, Peter: 77.0

Frequency of 77.0 is 6
-----------------------------------
Ray, Sherlock: 70.0

Frequency of 70.0 is 1
-----------------------------------
Lolly, Mike: 81.0

Frequency of 81.0 is 4
-----------------------------------
Watson, Peter: 78.0

Frequency of 78.0 is 6
-----------------------------------
Reynolds, Julio: 74.0

Frequency of 74.0 is 4
-----------------------------------
Sprouse, James: 77.0

Frequency of 77.0 is 7
-----------------------------------
Lee, Dilan: 82.0

Frequency of 82.0 is 2
-----------------------------------
Reynolds, Sherlock: 74.0

Frequency of 74.0 is 5
-----------------------------------
Watson, Julio: 78.0

Frequency of 78.0 is 7
-----------------------------------
Watson, Miranda: 74.0

Frequency of 74.0 is 6
-----------------------------------
Rayland, Miranda: 77.0

Frequency of 77.0 is 8
-----------------------------------
Holland, Miranda: 87.0

Frequency of 87.0 is 1
-----------------------------------
Watson, Julio: 79.0

Frequency of 79.0 is 1
-----------------------------------
Holland, Alicia: 82.0

Frequency of 82.0 is 3
-----------------------------------
Ray, Leena: 73.0

Frequency of 73.0 is 2
-----------------------------------
Rayland, Julio: 79.0

Frequency of 79.0 is 2
-----------------------------------
Rayland, James: 88.0

Frequency of 88.0 is 1
-----------------------------------
Reynolds, Alicia: 81.0

Frequency of 81.0 is 5
-----------------------------------
Ray, Peter: 87.0

Frequency of 87.0 is 2
-----------------------------------
Sharma, Dilan: 86.0

Frequency of 86.0 is 2
-----------------------------------
Sharma, Miranda: 79.0

Frequency of 79.0 is 3
-----------------------------------
Holmes, Divya: 83.0

Frequency of 83.0 is 1
-----------------------------------
Ray, Mike: 83.0

Frequency of 83.0 is 2
-----------------------------------
Reynolds, Peter: 83.0

Frequency of 83.0 is 3
-----------------------------------
Sharma, Mike: 89.0

Frequency of 89.0 is 3
-----------------------------------
Sharma, Miranda: 72.0

Frequency of 72.0 is 3
-----------------------------------
Rayland, Divya: 84.0

Frequency of 84.0 is 3
-----------------------------------
Sprouse, Peter: 77.0

Frequency of 77.0 is 9
-----------------------------------
Ray, James: 80.0

Frequency of 80.0 is 4
-----------------------------------
Lee, Divya: 89.0

Frequency of 89.0 is 4
-----------------------------------
Holland, Sherlock: 78.0

Frequency of 78.0 is 8
-----------------------------------
Lee, Dilan: 76.0

Frequency of 76.0 is 2
-----------------------------------
Lee, Divya: 75.0

Frequency of 75.0 is 4
-----------------------------------
Rayland, Julio: 80.0

Frequency of 80.0 is 5
-----------------------------------
Holland, Sherlock: 83.0

Frequency of 83.0 is 4
-----------------------------------
Lolly, Julio: 85.0

Frequency of 85.0 is 3
-----------------------------------
Sprouse, Alicia: 87.0

Frequency of 87.0 is 3
-----------------------------------
Holland, Dilan: 79.0

Frequency of 79.0 is 4
-----------------------------------
Ray, Alicia: 77.0

Frequency of 77.0 is 10
-----------------------------------
Lolly, Julio: 82.0

Frequency of 82.0 is 4
-----------------------------------
Sprouse, Dilan: 77.0

Frequency of 77.0 is 11
-----------------------------------
Sharma, Mike: 81.0

Frequency of 81.0 is 6
-----------------------------------
Rayland, Peter: 75.0

Frequency of 75.0 is 5
-----------------------------------
Ray, Miranda: 78.0

Frequency of 78.0 is 9
-----------------------------------
Holmes, Divya: 72.0

Frequency of 72.0 is 4
-----------------------------------
Holmes, James: 82.0

Frequency of 82.0 is 5
-----------------------------------
Watson, Julio: 75.0

Frequency of 75.0 is 6
-----------------------------------
Ray, James: 74.0

Frequency of 74.0 is 7
-----------------------------------
Holland, Dilan: 81.0

Frequency of 81.0 is 7
-----------------------------------
Watson, Miranda: 78.0

Frequency of 78.0 is 10
-----------------------------------
Lee, Alicia: 80.0

Frequency of 80.0 is 6
-----------------------------------
Sprouse, Leena: 79.0

Frequency of 79.0 is 5
-----------------------------------
Reynolds, Dilan: 80.0

Frequency of 80.0 is 7
-----------------------------------
Sharma, Peter: 80.0

Frequency of 80.0 is 8
-----------------------------------
Sprouse, Peter: 79.0

Frequency of 79.0 is 6
-----------------------------------
Sprouse, Miranda: 85.0

Frequency of 85.0 is 4
-----------------------------------
Holland, Sherlock: 81.0

Frequency of 81.0 is 8
-----------------------------------
Holland, Leena: 81.0

Frequency of 81.0 is 9
-----------------------------------
Rayland, Leena: 75.0

Frequency of 75.0 is 7
-----------------------------------
Sharma, Sherlock: 84.0

Frequency of 84.0 is 4
-----------------------------------
Rayland, Julio: 79.0

Frequency of 79.0 is 7
-----------------------------------
Rayland, Peter: 76.0

Frequency of 76.0 is 3
-----------------------------------
Sharma, Divya: 89.0

Frequency of 89.0 is 5
-----------------------------------