conforme segue, no netbeans ele roda, pelo prompt não…
Classe GradeBook:
package iniciando;
/**
*
* @author paulomv
*/
public class GradeBook {
private String courseName;
private final int[][] grades;
//Construtor de dois argumentos inicialia courseName e array de notas
public GradeBook(String name, int[][] gradesArray){
courseName = name;
grades = gradesArray;
}
//método para configurar o nome do curso
public void setCourseName(String name){
courseName = name;
}
//método para recuperar o nome do curso
public String getCourseName(){
return courseName;
}
//exibe a mensagem de boas-vindas
public void displayMessage(){
System.out.printf("Welcome to the grade book for \n%s!\n\n",
courseName);
}
//realiza as operações de dados
public void processGrades(){
outputGrades();
System.out.printf("\n%s %d\n%s %d\n\n",
"Lowest grade in the grade book is", getMinimum(),
"Highest grade in the grade book is", getMaximum());
outputBarChart();
}
//localiza nota mínima
public int getMinimum(){
int lowGrade = grades[0][0];
for(int[] studentsGrades : grades){
for(int grade : studentsGrades){
if(grade < lowGrade)
lowGrade = grade;
}
}
return lowGrade;
}
//localiza nota máxima
public int getMaximum(){
int highGrade = grades[0][0];
for(int[] studentsGrades : grades){
for(int grade : studentsGrades){
if(grade > highGrade)
highGrade = grade;
}
}
return highGrade;
}
//determina a média do conjunto de notas
public double getAverage(int[] setOfGrades){
int total = 0;
for(int grade : setOfGrades)
total += grade;
return (double) total / setOfGrades.length;
}
//gera sáida do gráfico de barras exibindo o total de notas
public void outputBarChart(){
System.out.println("Overall grade distribuition: ");
int[] frequency = new int[11];
for (int[] studentsGrades : grades){
for(int grade : studentsGrades)
++frequency[grade / 10];
}
for( int count = 0; count < frequency.length; count++){
if(count == 10)
System.out.printf("%5d> ", 100);
else
System.out.printf("%02d-%02d: ",
count * 10, count * 10 + 9);
for(int stars = 0; stars < frequency[count]; stars++)
System.out.print("*");
System.out.println();
}
}
//gera saída do conteúdo do array de notas
public void outputGrades(){
System.out.println("The grades are:\n");
System.out.print(" ");
for (int test = 0; test < grades[0].length; test++)
System.out.printf("Test %d ", test + 1);
System.out.println("Average");
for( int student = 0; student < grades.length; student++){
System.out.printf("Student %2d", student + 1);
for(int test : grades[student] )
System.out.printf("%8d", test );
double average = getAverage(grades[student]);
System.out.printf("%9.2f\n", average );
}
}
}
Método MAIN:
package iniciando;
/**
*
* @author paulomv
*/
public class Iniciando {
public static void main(String[] args) {
int[][] gradesArray = {{87, 96, 70},{68, 87, 90}, {94, 100, 90},
{100, 81, 82}, {83, 65, 85}, {78, 87, 65}, {85, 75, 83},
{91, 94, 100}, {76, 72, 84}, {87, 93, 73}};
GradeBook myGradeBook = new GradeBook(
"Introduction to Java Programming", gradesArray);
myGradeBook.displayMessage();
myGradeBook.processGrades();
}
}
Erro:
paulomv@paulomv-xxxxxx:~/NetBeansProjects/Iniciando/src/iniciando$ javac Iniciando.java
Iniciando.java:51: error: cannot find symbol
GradeBook myGradeBook = new GradeBook(
^
symbol: class GradeBook
location: class Iniciando
Iniciando.java:51: error: cannot find symbol
GradeBook myGradeBook = new GradeBook(
^
symbol: class GradeBook
location: class Iniciando
2 errors