-
Error: unexpected type
Hi, I have tried every way I could think to correct this problem. This is the last of 13 errors I had to find debugging this assignment.
Code:
interest = annualInterest 12;
after compiling it, the error message said:
Code:
possible loss of precision
found: double
required: int
the declaring variables are
int price, downPayment, tradeIn, months, loanAmt, interest;
double annualInterest, payment;
under conversions there is this:
Code:
annualInterest =Double.parseDouble(inputAnnualInterest);
under calculations the line of code is
Code:
interest = annualInterest 12;
I tried putting "/" in front of 12, got an error. Tried putting parantheses around
(annualInterest 12) got an error. How to get int when there is a double. I determined from declared variable annualInterest was the double. So here is what I tried next:
Code:
interest = (double = (annualInterest / 12));
got an error back
Code:
unexpected type
required: variable
found : class
interest = (double = (annualInterest / 12));
^(under the d in double)
1 error
My understanding is everything in the ( ) has to equate to an int and not double...since interest is an int. Must be close because the error message no longer says found: double required: int. It just says found:class required variable.
Maybe someone can clarify my understanding.
Thanks
-
Code:
interest = annualInterest / 12;
Think to yourself what are you DOING with interest. How do you get it. You weren't really doing anything to it. The interest might be better off as a double. In the future post all of your code.
Greetings.
-
This is called type casting, and if interest is of type double it's:
interest = (double)(annualInterest/12);
-
agreed with barney. If i am correct int uses 32 bits. Double uses double-precision 64 bits. You cant put a 64 bit value into 32, so the compiler shouts at you. Double is the largest datatype used by java.
This can give you more information if needed: Primitive Data Types (The Java™ Tutorials > Learning the Java Language > Language Basics)
Good luck