For Programmers: Free Programming Magazines  


Home > Archive > Java Help > April 2007 > SOS PLEASE FRIENDS OF JAVA









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author SOS PLEASE FRIENDS OF JAVA
mak

2007-04-27, 4:18 am

Good morning, how are you ?Last night i have been trying for two
hours to compile a quite big application in Java and i didn't do
anything!Could i have your help ?The application named GDB.java finds
the maximum and minimum grade of a class and the average grade and
stores these into arrays. The compiler error is illegal start of
expression at line public void outputGrades(){ .
The program is:
public class GDB{
private String courseName;
private int grades[][];
public GDB(String name,int gradesArray[][]){
courseName=name;
grades=gradesArray;

}
public void setCourseName(String name){
courseName=name;
}
public String getCourseName(){
return courseName;
}
public void displayMessage(){
System.out.printf("welcome to the GDB for \n%s!\n
\n",getCourseName());

}
public void processGrades(){
outputGrades();
System.out.printf("\n%s %d\n%s %d\n\n","min= ",getMinimum(),"max=
",getMaximum());
outputBarChart();
}
public int getMinimum(){
int lowGrade=grades[0][0];
for(int studentGrades[]:grades){
for(int grade:studentGrades){
if(grade<lowGrade)
lowGrade=grade;
}
}
return lowGrade;
}
public int getMaximum(){
int highGrade=grades[0][0];
for(int studentGrades[]:grades){
for(int grade:studentGrades){
if(grade>highGrade)
highGrade=grade;
}
}
return highGrade;

}
public double getAverage(int setOfGrades[]){
int total=0;
for(int grade:setOfGrades)
total+=grade;
return (double)total/setOfGrades.length;
}
public void outputBarChart(){
System.out.println("pantelh katanomh bathmon :");
int frequency[]=new int[11];
for(int studentGrades[]:grades){
for(int grade:studentGrades)
++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();



}
public void outputGrades()
{
System.out.println( "The grades are:\n" );
System.out.print( " " ); // align column heads

// create a column heading for each of the tests
for ( int test = 0; test < grades[0].length; test++ )
System.out.printf( "Test %d ", test + 1 );

System.out.println( "Average" ); // student average column
heading

// create rows/columns of text representing array grades
for ( int student = 0; student < grades.length; student++ )
{
System.out.printf( "Student %2d", student + 1 );

for ( int test : grades[ student ] ) // output student's
grades
System.out.printf( "%8d", test );

// call method getAverage to calculate student's average
grade;
// pass row of grades as the argument to getAverage
double average = getAverage( grades[ student ] );
System.out.printf( "%9.2f\n", average );
} // end outer for
} // end method outputGrades
} // end class GradeBook

RedGrittyBrick

2007-04-30, 8:24 am

mak wrote:
> Good morning,


Good morning mak, I guess its lucky I didn't read this message over the
wend or I might have read it at an inappropriate time of day!

Are you interested in help from people in different time zones? It might
be evening here when it is morning where you are. Does this matter to you?

> how are you ?


Thanks, for asking, I have a bruise on the top of my left foot which has
been troubling me a little.

How are you?

Are you planning a nice vacation this year?

What do you think about global warming?

Enough chit chat ...


> Last night i have been trying for two
> hours to compile a quite big application in Java and i didn't do
> anything!


Were you staring at the screen for two hours without even touching the
keyboard? I think I would have got up and made a cup of coffee or
something. To compile an application you definitely do need to do
something (e.g. type the command javac GDB.java or load an IDE). Maybe
you mean you didn't succeed?

> Could i have your help ?


Sure. I'd be happy to help. By the way, your politeness is appreciated
but I feel you may be overdoing it a little.

> The application named GDB.java finds
> the maximum and minimum grade of a class and the average grade and
> stores these into arrays.


I don't think I need to know that, but thanks for the info.

> The compiler error is illegal start of
> expression at line public void outputGrades(){ .


It means the compiler is expecting a new expression but "public void
outputGrades" doesn't look like an assignment, a "for" loop or any other
kind of expression.

Why does it expect an expression and not a method declaration? It must
be context, perhaps it thinks it is at a point where you should be
starting an expression and not at a point where you should be defining a
method. At what point can you declare a new method? Ususally after
closing the definition of the previous method?

I see you haven't closed the declaration of method outputBarChart() yet.

Perhaps you are missing a "}" on the line above?

> The program is:

<snipped>

Whenever I type "{", I follow up by pressing enter, "}", up-arrow, end,
enter. This habit ensures I almost never have this kind of problem.


P.S. I prefer it when people put the subject of their message in the
Subject: line of their message. Capitals are considered SHOUTING, which
I find a little irritating, especially in the morning :-)
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com