Results 1 to 2 of 2
Thread: Need help with Scanner/hasNext
- 03-17-2012, 10:48 PM #1
Member
- Join Date
- Mar 2012
- Posts
- 1
- Rep Power
- 0
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:
Mike Johnson
1590.45
Christina Alve
450.50
Peter Fort
1342.12
etc..
etc
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.
while (inputFile.hasNext())
{
String str = inputFile.nextLine();
if (inputFile.hasNextDouble())
{
inputFile.nextLine();
System.out.println(str);
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.
- 03-18-2012, 12:40 AM #2
Similar Threads
-
hasNext, Ctrl-Z not working
By kahwawashay in forum New To JavaReplies: 15Last Post: 05-12-2012, 09:16 AM -
How to use Scanner ?
By sandeep43 in forum New To JavaReplies: 7Last Post: 08-10-2011, 01:29 PM -
Scanner to int?
By N00Bie in forum New To JavaReplies: 6Last Post: 02-12-2011, 12:14 AM -
hasNext call
By scotts in forum New To JavaReplies: 4Last Post: 06-20-2010, 03:58 PM -
Using scanner.hasNext() but recognize return
By ScKaSx in forum New To JavaReplies: 5Last Post: 01-27-2009, 10:11 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks