У меня было хорошее начало, но я застрял, пытаясь найти самый низкий и самый высокий класс массива. Я также должен найти средний класс всего массива.
Они сказали, что этот сайт быллучшее место, чтобы получить помощь
ТАК ... если кто-нибудь может мне помочь, я буду признателен за это
Это то, что у меня есть до сих пор
import java.util.Scanner;
public class Grades
{
public static void main(String[]args)
{
Scanner keyboard = new Scanner(System.in);
String studentName;
double studentScore;
double [][]studentTestScores;
double Average ;
char LetterGrade;
double LowestScore;
final int numStudents = 2;
final int numGrades = 3;
Grades2 class1 = new Grades2 (numStudents,numGrades );
studentTestScores = class1.getTestScoresArray();
for( int StudentIndex = 0; StudentIndex < numStudents; StudentIndex++)
{
System.out.println("Enter name of student " + (StudentIndex + 1));
studentName = keyboard.nextLine();
class1.setStudentName( studentName );
for( int studentScoreIndex = 0; studentScoreIndex < numGrades; studentScoreIndex++)
{
System.out.println("Enter test grade " + (studentScoreIndex + 1) + " grade of " + studentName);
studentScore = keyboard.nextDouble();
while( studentScore < 0 || studentScore > 100){
System.out.println("Please enter a valid
score" + (studentScoreIndex + 1) + " for " +
studentName);
studentScore = keyboard.nextDouble();
}
keyboard.nextLine();
class1.setScore(StudentIndex, studentScoreIndex, studentScore );
}
}
for( int StudentIndex = 0; StudentIndex < n
umStudents; StudentIndex++ ){
System.out.print( class1.getStudentName(
StudentIndex ) + " Test scores are ");
Average = class1.AverageTestScore(
studentTestScores[ StudentIndex ] );
LetterGrade = class1.getLetterGrade( Average );
LowestScore = class1.getLowestScore(
studentTestScores[ StudentIndex ] );
for( int studentScoreIndex =
0;studentScoreIndex < numGrades;
studentScoreIndex++){
if( studentScoreIndex != numGrades -1){
System.out.print( studentTestScores[
StudentIndex ][ studentScoreIndex ] + ", " );
} else {
System.out.print( studentTestScores[
StudentIndex ][ studentScoreIndex ] + " " );
}
}
System.out.println("with an average of " +
String.format(" %.2f", Average) + ", letter grade "
+ LetterGrade );
System.out.println("\nLowest grade is " +
LowestScore);
System.out.println();
}
}
}
Вот часть2 программы
import java.util.ArrayList;
public class Grades2
{
private ArrayList <String> studentNames = new
ArrayList <String> ();
private char [] LetterGrades = {'A', 'B', 'C' , 'D'
,
'F' };
private double [] [] studentTestScores;
public String getStudentName(int studentIndex){
return studentNames.get(studentIndex);
}
public double AverageTestScore( double []
studentTestScores){
double studentTestScoresTotal = 0;
double studentTestScoresAverage;
for( int studentTestScore = 0; studentTestScore <
studentTestScores.length; studentTestScore++){
studentTestScoresTotal = studentTestScoresTotal
+ studentTestScores[ studentTestScore];
}
studentTestScoresAverage = studentTestScoresTotal
/ studentTestScores.length;
return studentTestScoresAverage;
}
public double getLowestScore(){
double LowestScore = studentTestScores[0] ;
for( int studentTestScore = 0; studentTestScore <
studentTestScores.length; studentTestScore++){
if ( studentTestScores[scoreIndex] <
LowestScore){
LowestScore = studentTestScores[scoreIndex];
}
}
return LowestScore;
}
public char getLetterGrade( double TestScoreAverage
)
{
char LetterGrade = 'Z';
if(TestScoreAverage < 60 ){
LetterGrade = 'F';
} else if ( TestScoreAverage < 70){
LetterGrade = 'D';
} else if ( TestScoreAverage < 80){
LetterGrade = 'C';
} else if ( TestScoreAverage < 90){
LetterGrade = 'B';
} else if ( TestScoreAverage < 100){
LetterGrade = 'A';
}
return LetterGrade;
}
public void setStudentName(String studentName){
studentNames.add(studentName);
}
public void setScore(int studentIndex, int
scoreIndex, double Score){
studentTestScores[ studentIndex ][ scoreIndex ] =
Score;
}
public double [][] getTestScoresArray(){
return studentTestScores;
}
public Grades2( int numStudents, int numGrades){
studentTestScores = new double [ numStudents ][
numGrades ];
}
}