這是原創,我嘗試過,因爲我想知道如果它只是原來是錯的,我很抱歉沒有清除我的問題,而不是特別希望你能幫助傢伙。
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