• Post Reply Bookmark Topic Watch Topic
  • New Topic

Scanner issues  RSS feed

 
Ansya Bluerose
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I'm working on an assignment for class, and I keep getting the error "Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: java.util.Scanner.nextint
at programming.assignment.pkg1.ProgrammingAssignment1.main(ProgrammingAssignment1.java:9)"

I'm not entirely sure what this means. Can someone point me in the right direction to determine how to fix it? I want to learn why this is and what to do, not necessarily have the code fixed for me (as that would be cheating).
Thanks for any help you can provide!
 
Stefan Evans
Bartender
Posts: 1837
10
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is rather a cryptic error message.

Erroneus sym type: java.util.Scanner.nextint

== Erroneous sym type --> Erroneous Symbol --> You used the name of something that the compiler did not understand
It then tells you the name it can't understand: java.util.Scanner.nextint

Looking at the line of code, it is probably this one:

It doesn't like the nextint method here. What could be wrong with it?

Refer to the javadoc for java.util.Scanner class and see if you have spelled the method name correctly.
Case is important!


Edit:
I'm just wondering what you are using to get this error message ? How are you writing, compiling and running this code?
I would suggest using "javac ProgrammingAssignment1.java" to compile it. That will probably give you better error messages.
RuntimeException means that something in java was actually running.

 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch

As Stefan says, you can have tiny spelling errors which are really hard to see.
 
Ansya Bluerose
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stefan Evans wrote:That is rather a cryptic error message.

Erroneus sym type: java.util.Scanner.nextint

== Erroneous sym type --> Erroneous Symbol --> You used the name of something that the compiler did not understand
It then tells you the name it can't understand: java.util.Scanner.nextint

Looking at the line of code, it is probably this one:

It doesn't like the nextint method here. What could be wrong with it?

Refer to the javadoc for java.util.Scanner class and see if you have spelled the method name correctly.
Case is important!


Edit:
I'm just wondering what you are using to get this error message ? How are you writing, compiling and running this code?
I would suggest using "javac ProgrammingAssignment1.java" to compile it. That will probably give you better error messages.
RuntimeException means that something in java was actually running.



OK, so here's the updated code:


It appears as though I needed to capitalize the I in "nextInt()".

Now, for the next question on this assignment, I need to set it up to allow "number1" to accept non-integer numbers (as interest rates are percentages). Where can I find an explanation for how to do this?

Thanks again for all the help!

EDIT: I'm using Netbeans IDE 8.0.2
 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I never knew you get compilation problem error messages in NetBeans as well as in Eclipse. Next time, you should believe the IDE when it tells you about errors. You should look at the code and you will probably find red marks against the lines with errors. You may even get hints about correcting them if you hover your mouse over the red marks.

You set up non‑integer numbers the same way you set up any other non‑integer. I presume you have come across floating‑point arithmetic? I presume you have read all the methods in the Scanner class?

By the way, run lines 8 and 9 together
int number = input.nextInt(); (etc)
Use variable names which mean something. A name like number is particuarly useless.
 
Ansya Bluerose
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:I never knew you get compilation problem error messages in NetBeans as well as in Eclipse. Next time, you should believe the IDE when it tells you about errors. You should look at the code and you will probably find red marks against the lines with errors. You may even get hints about correcting them if you hover your mouse over the red marks.

You set up non‑integer numbers the same way you set up any other non‑integer. I presume you have come across floating‑point arithmetic? I presume you have read all the methods in the Scanner class?

By the way, run lines 8 and 9 together
int number = input.nextInt(); (etc)
Use variable names which mean something. A name like number is particuarly useless.


OK, dug into using floating-point variables (the "double" keyword". From there, Scanner uses the "nextDouble()" method to indicate that the next input will be a floating-point variable. As such, the final code is as follows:



Tested for syntax errors, none to speak of.
Tested for logical errors, none to speak of.
Looks good!

Of note, my professor is a tricky little bugger-The formula he provided for the program uses the monthly interest rate, but all of the examples to test with provided the annual interest rate.

Thanks again to everyone for all their help!
 
Stefan Evans
Bartender
Posts: 1837
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just some more feedback on code style/conventions.
I don't know if you get any marks for that in your assignments, but in my opinion you should :-)
Most of these might seem nit-picky but they are still important.

#1 Use of Capital Letters.
Classes start with a Capital letter. e.g. ProgrammingAssignment
Variables start with a lower case letter. e.g. investment, rate, years should all start with lower case letters.
After that each new 'word' should start with a capital. e.g. initialInvestmentAmount, interestRate, numberOfYearsToInvest

#2 indentation : looks good :-)

#3 Constants
The 'magic' numbers 12 and 1200. What do they represent?
I presume 12 relates to the number of months in a year. Where does 1200 come from?
It would be nice to represent 'magic' numbers like these as constants.
i.e. public static final int MONTHS_IN_YEAR = 12



 
Ansya Bluerose
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stefan Evans wrote:Just some more feedback on code style/conventions.
I don't know if you get any marks for that in your assignments, but in my opinion you should :-)
Most of these might seem nit-picky but they are still important.

#1 Use of Capital Letters.
Classes start with a Capital letter. e.g. ProgrammingAssignment
Variables start with a lower case letter. e.g. investment, rate, years should all start with lower case letters.
After that each new 'word' should start with a capital. e.g. initialInvestmentAmount, interestRate, numberOfYearsToInvest

#2 indentation : looks good :-)

#3 Constants
The 'magic' numbers 12 and 1200. What do they represent?
I presume 12 relates to the number of months in a year. Where does 1200 come from?
It would be nice to represent 'magic' numbers like these as constants.
i.e. public static final int MONTHS_IN_YEAR = 12





As you say, 12 represents the number of months in the year. 1200 is indicative of the fact that we are using the annual percentage as the input, where the formula needs the monthly (so, for example, if the annual interest rate is 3.25% (or 0.0325), then the monthly interest rate in plain terms is approximately .271% (or 0.00271). This is actually something that tripped me up for a bit, as I kept running the numbers he provided as examples both through the program and by hand, and I was not getting the same results he was. It wasn't until I realized that the interest rate provided was not the one being used in the formula that I adjusted the numbers to reflect this, and lo and behold it worked.

I'll have to look into constants, and thank you for the formatting advice!
 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ansya Bluerose wrote: . . . my professor is a tricky little bugger . . .
That last word may be permissible where you are writing but it isn't where I am reading; please avoid it in future.

So, is the interest at (rate) per month
1.0 + rate × 12 − 1.0
or
(1.0 + rate)¹² − 1.0?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!