我对java很陌生-
我有一个文本文件,其中包含有关员工工资和每周工作时间的数据。我需要弄清楚如何在跳过每个部分上方的文本标题的同时阅读数据,然后准备好数据,以便我可以对其执行一些简单的计算。
这是输入文件的示例:
Shop One
4
26 8
13 6.5
17 6
32 7.5
Shop Two
1
42 8
Shop Three
0
第一个数字是员工人数,然后是每个员工的工时和工资。
这是我到目前为止所得到的:
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"); }
我想我需要一种方法来跳过文件的“Shop One”部分并阅读数字。我似乎无法弄清楚如何,我只是不断收到 InputMismatchException。任何帮助将不胜感激。