Hi guys

I need some help writing a program where I store information from a textfile into a parallel array. I need to be able to do a multiplication sum with the amount,and an if statement.

Here is the textfile
James 550
Quinton 410
Liam 120
Taylor 600
Jake 270

(These are truckdrivers,and the miles they drove in a month).

I would appreciate it if someone could help me or give me a link which could help with this,I am still new to arrays.

Thanks in advance

5 Years
Discussion Span
Last Post by _eclipse
  public class drivers

    Scanner scan = new Scanner(new File("drivers.txt"));
        String line = scan.nextLine();
        String[] token = line.split(" ");  // name is in token[0] distance in token[1]

I'm stuck here at the moment,I'm getting a few errors and I'm not sure how to continue,the next thing I want to do is put an if-statement in,so that it gives 'n notification when more than 500 miles is driven.


I'm getting a few errors

You need to post the full text of any error messages that you need help with.

not sure how to continue

To see what is in the token array use the Arrays class's toString() method to format the array for output: System.out.println("an ID "+ java.util.Arrays.toString(theArrayName));
Replace "an ID" with a description of what is being printed.

What does the assignment say you need to do with the tokens that are in the array?

Edited by NormR1


I resolved the errors ...
Here is exactly what I have to do :
1.import the data from the textfile and store it in arrays
2.write an if statement to alert the user if a driver has done more than 500 miles
3.Times the miles driven by $10 (drivers are paid $10 per mile).
4. Display the salary of each driver

Note : This isn't really an asignment,it is just an activity I took from a book for practice. So there isn't any specific limitations to how I can or cannot do it,aslong as I get the needed output.

Edited by _eclipse


Which of those 4 steps are you working on? Do one at a time: code it, compile and test it.
When it works move to the next one.
When you have problems and want help, post your questions here.


I'm busy with the first step,but I'll try again. A last question,which packages should I import with the scanner code I posted,for example import.io* ?


... which packages should I import ... ?

For any Java API class, just Google for the Java API documentation for the class, and you will see the fully-qualified package name as the very first line. That's the exact thing you need to import.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.