• Please be sure to read the rules and adhere to them. Some banned members have complained that they are not spammers. But they spammed us. Some even tried to redirect our members to other forums. Duh. Be smart. Read the rules and adhere to them and we will all get along just fine. Cheers. :beer: Link to the rules: https://www.forumsforums.com/threads/forum-rules-info.2974/

Any Java programmers out there?

bczoom

Super Moderator
Staff member
GOLD Site Supporter
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.
 
Top