Need help with Scanner/hasNext
Hey I'm new to java and having trouble with one of my assignments. I have a txt file that looks like this:
It's names with their corresponding sales listed consecutively. I have to calculate the payroll and display the output listing the names only in one column and Commission from sales in another. Iv'e figured out how to only get the names using hasNextDouble and nextLine. Otherwise it would keep giving me a Mismatched exception error because the first line is a string.
String str = inputFile.nextLine();
So my question is how do I extract the sales individually and store them so I can calculate commission/bonus? I can't hardcode any of the numbers and limited to using scanner only.
Any help is appreciated, thanks.
Re: Need help with Scanner/hasNext
The Scanner class has a small quirk. The nextLine method will read an end-of-line but the nextDouble(nextInt etc) methods do not read the EOL. So you must do that yourself if you want to continue reading data.