Need help with something as I don't know Java. (I'm an old COBOL programmer). Any/all help greatly appreciated.
Trying to compute an average GPA.
My pasting doesn't show indentations.
Here's the code:
public class averageGPA
{
double gpa;
//double sum;
public averageGPA(double a) //order of info
{
gpa = a;
}
public averageGPA gpa1 = new averageGPA(2.9);
public averageGPA gpa2 = new averageGPA(4.0);
public averageGPA gpa3 = new averageGPA(3.9);
public averageGPA gpa4 = new averageGPA(3.0);
public double averageGPA(double gpa)
{
double sum;
sum=gpa1+gpa2+gpa3+gpa4; //GPA is added
int totalStudents = 4; //total students
double averageGPA = sum/totalStudents; //divdie GPA by the number of students
return averageGPA; //return average to display
}
}
It doesn't like the line in red.
Returned error is
"bad operand types for binary operator '+'.
first type: averageGPA
second type: averageGPA
Any ideas? Looks like a storage definition error to me but I don't know Java.
Trying to compute an average GPA.
My pasting doesn't show indentations.
Here's the code:
public class averageGPA
{
double gpa;
//double sum;
public averageGPA(double a) //order of info
{
gpa = a;
}
public averageGPA gpa1 = new averageGPA(2.9);
public averageGPA gpa2 = new averageGPA(4.0);
public averageGPA gpa3 = new averageGPA(3.9);
public averageGPA gpa4 = new averageGPA(3.0);
public double averageGPA(double gpa)
{
double sum;
sum=gpa1+gpa2+gpa3+gpa4; //GPA is added
int totalStudents = 4; //total students
double averageGPA = sum/totalStudents; //divdie GPA by the number of students
return averageGPA; //return average to display
}
}
It doesn't like the line in red.
Returned error is
"bad operand types for binary operator '+'.
first type: averageGPA
second type: averageGPA
Any ideas? Looks like a storage definition error to me but I don't know Java.