I'm very new to java -
I've got a text file with data about employee wages and hours worked per week. I need to figure out how I can read through the data whilst skipping the text headings above each section, and then have the data ready so that I can perform a couple of simple calculations on it.
This is a sample of the input file:
Shop One
4
26 8
13 6.5
17 6
32 7.5
Shop Two
1
42 8
Shop Three
0
The first number is the employee count, followed by each employee's hours and wage.
Here's what I've got so far:
import java.io.*;
import java.util.*;
public class program3
{
static Scanner console = new Scanner(System.in);
public static void main(String[] args) throws FileNotFoundException
{
System.out.println("Please enter your recommended maximum total staff cost per week: ");
double RM = console.nextDouble();
Scanner inFile = new Scanner(new FileReader("inFile.txt"));
int shopStaff;
for (int i = 0; i < (shopStaff = inFile.nextInt()); i++) //number of times loop executes will be equal to number of staff
{
double shop1Tot = 0;
double shop1SH = inFile.nextDouble(); //shop1SH = Shop One Staff Hours
double shop1SW = inFile.nextDouble(); //shop1SW = Shop One Staff Wage
shop1Tot = shop1Tot + (shop1SH * shop1SW); //calculates total staff wages per week
{
if (shop1Tot <= RM) {
System.out.println("details written to outFile");
PrintWriter outFile = new PrintWriter ("outFile.txt");
outFile.println("details"); }
else if (shopTot > RM){
System.out.println("details written to screen only"); }
I guess I need a way to skip over the "Shop One" part of the file and just read the numbers. I cant seem to figure out how, I just keep getting an InputMismatchException. Any help would be greatly appreciated.