Extra credit: Write two additional methods for the StudentGrades class--one method for returning the median grade and one method for returning the mode.
This is what I have for now....
import java.util.*;
import java.io.*;
public class STUDENT_GRADES
{
public static void main(String[] args)
{
double avg;
int a;
int totStudents = 15;
int highestGrade = 100;
int grades[] = new int[highestGrade];
for (int i = 0; i <= totStudents; i++)
{
grades[i] = (int)(Math.random() * 100) + 1;
}
for (int i = 1; i <= totStudents; i++)
{
System.out.println("Student number " + i + "'s grade is: " + grades[i]);
}
System.out.println("\nThe grades for the 15 students are as follows:");
bubbleSort(grades, 15);
for (a = 0; a < 15; a++)
System.out.print(grades[a] + " ");
System.out.println("");
System.out.print("\nThe highest grade in the class is: " + grades[14]);
System.out.print("%");
System.out.println("");
avg = ((grades[0] + grades[1] + grades[2] + grades[3] + grades[4] + grades[5] + grades[6] + grades[7] +
grades[8] + grades[9] + grades[10] + grades[11] + grades[12] + grades[13] + grades[14]) / totStudents);
System.out.printf("The average of the class is: %.2f", avg);
System.out.print("%");
System.out.println("");
}
//Method bubbleSort
public static void bubbleSort(int grades[], int gradesLength)
{
//Initializing and declaring variables
int fNow;
int count;
int numbers;
//Starting loop to sort
for (count = 0; count < gradesLength; count++)
{
//Starting loop inside of sort loop for total list
for (numbers = 0; numbers < gradesLength - 1; numbers++)
//Declaring how list is formatted
if (grades[numbers] > grades[numbers + 1])
{
//Declaring new order of list
fNow = grades[numbers];
grades[numbers] = grades[numbers + 1];
grades[numbers + 1] = fNow;
}
}
}
STUDENT_GRADES()
{
int totStudents = 15;
}
}

New Topic/Question
Reply



MultiQuote





|