• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 75
Android Chrome Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author & internet detective
Posts: 41907
909
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79412
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Anderson gave himself the promotion. So I gave myself this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic