aspose file tools*
The moose likes Beginning Java and the fly likes java:40: error: bad operand types for binary operator '/' Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "java:40: error: bad operand types for binary operator Watch "java:40: error: bad operand types for binary operator New topic
Author

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

JeffreyAaron Smith
Greenhorn

Joined: Jan 26, 2013
Posts: 4
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

Joined: Sep 28, 2012
Posts: 75

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.


Da mihi sis bubulae frustum assae, solana tuberosa in modo Gallico fricta ac quassum lactatum coagulatum crassum.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30780
    
157

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
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.
 
 
subject: java:40: error: bad operand types for binary operator '/'