Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java:40: error: bad operand types for binary operator '/'

 
JeffreyAaron Smith
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please forgive me ignorance, but I'm pulling my hair out...and I don't have much left.

The errors I'm getting are:

40: error: bad operand types for binary operator '/'
gradePoints = (earnedPoints / possiblePoints);
^
first type: int[]
second type: int[]
47: error: bad operand types for binary operator '<'
if (gradePoints < .60)
^
first type: double[]
second type: double
49: error: bad operand types for binary operator '>='
else if (gradePoints >= .60 && gradePoints < .70)
^
first type: double[]
second type: double
49: error: bad operand types for binary operator '<'
else if (gradePoints >= .60 && gradePoints < .70)
^
first type: double[]
second type: double
51: error: bad operand types for binary operator '>='
else if (gradePoints >= .70 && gradePoints < .80)
^
first type: double[]
second type: double
51: error: bad operand types for binary operator '<'
else if (gradePoints >= .70 && gradePoints < .80)
^
first type: double[]
second type: double
53: error: bad operand types for binary operator '>='
else if (gradePoints >= .80 && gradePoints < .90)
^
first type: double[]
second type: double
53: error: bad operand types for binary operator '<'
else if (gradePoints >= .80 && gradePoints < .90)
^
first type: double[]
second type: double
55: error: bad operand types for binary operator '>='
else if (gradePoints >= .90 && gradePoints <= 1.00)
^
first type: double[]
second type: double
55: error: bad operand types for binary operator '<='
else if (gradePoints >= .90 && gradePoints <= 1.00)
^
first type: double[]
second type: double
57: error: cannot return a value from method whose result type is void
return getLetterGrade;
^
67: error: method getLetterGrade in class JSHwScore cannot be applied to given types;
+ possiblePoints + " possible points: " + getLetterGrade(earnedPoints), possiblePoints);
^
required: double,double
found: int[]
reason: actual and formal argument lists differ in length
12 errors

Tool completed with exit code 1


------------------------


The java code is:



-------------------------------


Any help you can give would be greatly appreciated.
 
Aj Prieto
Ranch Hand
Posts: 75
Android Chrome Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The first thing you should read are the error messages. After, you'd see that you're using a math operator on an array which you can't do.

To fix this, you'd have to take an element out of the array.

i.e.


Also, it looks like you never declare a size for you gradePoints array.

Though from your gradePoints() method, I don't think gradePoints should have been declared as an array in the first place.

Another thing, a comment about your comments. I think its rather useless to put an "//End constructor" or any other type of "//End ..." comment.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34973
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeffrey is having a problem posting. While we work with him on the error, here's what he wanted to post:

~~~~~~~~~~~~~~~~~~~~~~~~~~
Thanks for your reply, but I'm still not resolving my problems. I've spent hours trying to fix it with your suggestion and every thing I try, seems to cause two more errors. I've attached my original driver and driven classes that I couldn't seem to fix. Perhaps this is the direction I should be still working on. I would appreciate it if you could look at these to see if you might be able to determine my short comings. The problem with this version is the output only produces the last grade of the array "On this homework, you earned 16.0 out of 20.0 possible points: B" three times and then the overall grade line (correctly).

Driver:


Driven:


Once again, I really appreciate your time and effort in helping me figure this out. I'm taking a Java class and when I read the book, I think I get what it's saying, but when I write the code, I obviously am not really getting it.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50208
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Teh answer has already been given: You can apply the / operator to one of the primitive number types, which are byte char short int long float and double, and nothing else. You would have to get one of the elements of your arrays, then you can divide them.
int i = numbers[123] / numbers[234]; …which requires a certain size for your numbers array and which will not work if the right‑hand operand turns out to be 0.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic