这是原创,我尝试过,因为我想知道如果它只是原来是错的,我很抱歉没有清除我的问题,而不是特别希望你能帮助家伙。
private static final double FULL_TIME = 40.0;
static Scanner scanner = new Scanner(System.in);
static String nameOfEmployee;
static double hourlyRate;
static double hoursWorked;
static double taxRate;
static double grossAmount = 0;
static double netAmount = 0;
static double TOtalGrossAmount = 0;
static double TotalNetAmount = 0;
private static Scanner ian;
public static void main (String []args) throws IOException
{
Instructions();
PayrollReport();
printEmployeeInfo(nameOfEmployee, hourlyRate, hoursWorked, taxRate, grossAmount, netAmount);
}
public static void Instructions()
{
System.out.println("\t\t\t\t\t\tInstructions for Payroll Report Program" +
"\n\t\t\t\tThis program calculates a paycheck for each employee." +
"\n\t\t\t\tA text file containing the following information will be created." +
"\n\t\t\t\tname, pay rate, hours worked, and tax percentage to be deducted");
System.out.println("\n\t\t\t\tThe program will create a report in columnar format showing the " +
"\n\t\t\t\ttemployee name, hourly rate, number of worked, tax rate," +
"\n\t\t\t\tgross pay, and netpay.");
System.out.println("\n\t\t\t\tAfter all emplyoees are processed , totals will be displayed," +
"\n\t\t\t\tincluding total gross amount and total net pay.");
}
public static void PayrollReport()
{
{
System.out.println("\n\t\t\t\t\t\t\t\tPayroll Report ");
System.out.print("");
System.out.print("\n\t\t\t\tEmployee Name " + " Hourly Rate " + " Hours Worked " + " Tax Rate " + " Gross Amount " + " Net Amount");
System.out.print("");
System.out.println("\n\t\t\t\t--------------- " + " ----------- " + " ------------" + " --------- " + " ----------- " + " -----------");
}
}
public static void printEmployeeInfo(String nameOfEmployee , double HourlyRate , double HoursWorked ,
double TaxRate , double GrossAmount , double NetAmount) throws IOException
{
try
{
ian = new Scanner(new File("payroll.dat"));
}
catch (IOException e)
{
e.printStackTrace();
}
while (ian.hasNext())
{
nameOfEmployee = ian.nextLine();
HourlyRate = ian.nextInt();
HoursWorked = ian.nextInt();
TaxRate = ian.nextInt();
GrossAmount = 0;
NetAmount = 0;
TOtalGrossAmount += GrossAmount ;
TotalNetAmount += NetAmount;
System.out.printf("%s %s %s %s %s %s \n" , "\t\t\t\t" , nameOfEmployee , " "
, HourlyRate , " " , HoursWorked , " " , TaxRate , GrossAmount, NetAmount);
}
System.out.printf(" " , TOtalGrossAmount + " " + TotalNetAmount);
ian.close();
}
}
要获得正确的理由例外不仅在扫描仪类的实例 – 2015-03-19 10:17:26
几乎你应该包内'try'和'catch'块,你的代码确定你不需要ian.nextLine(),nextInt应该自己换成新行。另外,你确定所有的值都是int,而不是小数? – 2015-03-19 10:19:41
很明显,文件内容和阅读方式之间存在不匹配!但除非您向我们展示一些意见,否则我们无法告诉您原因。 – 2015-03-19 10:19:50