I am currently working through a task in my new placement. Basically what I need to do is get numbers from a file and multiply them. My file read as follows
Dave
7 35
Lucy
6 19
I need to get the numbers for each person and multiply them so I can use them later on, I have this code so far, I'm sure there is a simpler way as this seems very long winded. The print to screen is there simply to test if it works.
import java.util.*;
import java.io.*;
import javax.swing.JOptionPane;
public class Task1
{
public static void main(String[] args) throws FileNotFoundException
{
Scanner inFile = new Scanner(new FileReader("ExternalData.txt"));
String name;
double rate;
double hours;
name = inFile.next ();
rate = inFile.nextDouble();
hours = inFile.nextDouble();
double weeklypay1 = rate * hours;
String name2;
double rate2;
double hours2;
name2 = inFile.next ();
rate2 = inFile.nextDouble();
hours2 = inFile.nextDouble();
double weeklypay2 = rate * hours;
System.out.println("Daves pay:" + weeklypay2);
}
}
My question is basically does this look like a good way to lay it out or am I going completely the wrong way about it, very new to java so would appreciate any help, thanks in advance!