• 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

How to fix bad operand types for binary operator?

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have several class for my CourseGrades class. I'm trying to find out average of them and the lowest & the highest number among them.
Can anyone please help me with this? I'm getting following error msg:

CourseGrades.java:34: error: inconvertible types
total += (double)(grades[i]);
^
required: double
found: GradedActivity
CourseGrades.java:45: error: bad operand types for binary operator '>'
if ((grades[0]>grades[1])&& (grades[0]>grades[2]) && (grades[0]>grades[3]))
^
first type: GradedActivity
second type: GradedActivity
CourseGrades.java:45: error: bad operand types for binary operator '>'
if ((grades[0]>grades[1])&& (grades[0]>grades[2]) && (grades[0]>grades[3]))
^
first type: GradedActivity
second type: GradedActivity
CourseGrades.java:45: error: bad operand types for binary operator '>'
if ((grades[0]>grades[1])&& (grades[0]>grades[2]) && (grades[0]>grades[3]))
^
first type: GradedActivity
second type: GradedActivity
CourseGrades.java:47: error: bad operand types for binary operator '>'
else if ((grades[1]>grades[0])&& (grades[1]>grades[2]) && (grades[1]>grades[3]))
^
first type: GradedActivity
second type: GradedActivity
CourseGrades.java:47: error: bad operand types for binary operator '>'
else if ((grades[1]>grades[0])&& (grades[1]>grades[2]) && (grades[1]>grades[3]))




//***********************************************************************
[Fixed code tags and formatted - see UseCodeTags for details]
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Aunu. Welcome to the Ranch!

It looks like you're trying to cast a GradedActivity object (which is what grades[i] is) to a double. Why would you expect that to work? Presumably you intend that to be the score of the GradedActivity?

The same elsewhere - you're trying to use an object as if it was a number.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome again

I think you need a new way to iterate the array and find which is the largest; it is a standard beginner's exercise and quite simple to implement. Those multiple ifs are inelegant, I am afraid, and potentially error‑prone.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic