• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

compilation errors: possible loss of precision, incompatible types

 
Ben Hultin
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am running into this error:





^
BenHultinProg2.java:46: incompatible types
found : java.lang.String
required: double
double totalPPoints = hw1.getPPoints() + hw2.getPPoints() + hw3.
getPPoints() + hw4.getPPoints();

^
BenHultinProg2.java:53: possible loss of precision
found : double
required: int
switch (lGrade) {
^




I am stumped about both of these errors, I have no idea how Strings got involved in the code and I have removed all traces of ints as well for the second error, yet it still persists.

here is my driver class:




my driven class is:



I appreciate any suggestions you have:
 
Rob Spoor
Sheriff
Pie
Posts: 20661
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Those are not your real compiler errors; I don't get the first one about String and double when I try your code.

As for the second one, switch statements can only accept int and smaller (byte, short and char). long, float and double are not allowed. Also, you entire switch structure is illegal. Switch statements only work on exact values. For example:
You'll need to switch to an if-statement:
 
Ben Hultin
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for the pointer, I will be sure to remember that detail. after making a a couple adjustments I was able to get rid of the errors above. Thanks again for the help.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic