Как мне в дополнение к отображению цифр заработной платы на экране сохранить их в простом текстовом файле?
Выходные данные не могут быть сохранены в Payroll.txt мне нужна помощь в их хранении
Что я уже пробовал:
PrintWriter out = new PrintWriter(new FileWriter("Payroll.txt", true)); out.printf( ); double hourlyPay = 0.00; Scanner input = new Scanner(System.in); System.out.println("Enter worker name: "); String name = input.nextLine(); System.out.println("Choose your skill level: 1, 2, 3: "); int skillLevel = input.nextInt(); switch(skillLevel) { case 1: hourlyPay = 17.00; break; case 2: hourlyPay = 20.00; break; case 3: hourlyPay = 22.00; break; default: System.out.println("Error: invalid skill level."); } if (skillLevel > 0 && skillLevel < 4) { System.out.println("How many hours did you work? : "); int regularHours = input.nextInt(); int overtimeHours = 0; if (regularHours > 40) { overtimeHours = regularHours - 40; regularHours = 40; } double regularPay = (double)regularHours * hourlyPay; double overtimePay = (double)overtimeHours * hourlyPay * 1.5; int totalHours = regularHours + overtimeHours; double totalPay = regularPay + overtimePay; String retirement = ""; String insure = ""; double retirementPlan = totalPay * 0.030; double itemizedDeductions = 0.00; int numSelections = 0; int choice; if (skillLevel == 2 || skillLevel == 3) { do { System.out.println("Would you like (1) medical insurance, (2) dental insurance, and/or (3) Long Term Disability Insurance? Press 0 to skip."); choice = input.nextInt(); ++numSelections; if (choice == 1) { itemizedDeductions += 32.50; insure = "Medical Insurance"; } else if (choice == 2) { itemizedDeductions += 20.00; insure = "Dental Insurance"; } else if (choice == 3) { itemizedDeductions += 10.00; insure = "Long Term Disability Insurance"; } else { System.out.println("You have chosen to skip the insurance options."); choice = 0; } } while(choice != 0 && numSelections < 3); } if (skillLevel == 3) { System.out.println("Would you like to participate in the retirement plan? (1) Yes (2) No"); int retirementYesNo = input.nextInt(); if (retirementYesNo == 1) { itemizedDeductions += retirementPlan; System.out.println("Would you like (1) Savings Incentive Match Plans for Employees, (2) Simplified Employee Pension , and/or (3) Salary Reduction Simplified Employee Pension?"); int retire = input.nextInt(); if (retire == 1 ) { retirement = "Savings Incentive Match Plans for Employees"; } else if (retire == 2) { retirement = "Simplified Employee Pension"; } else if (retire == 3) { retirement = "Salary Reduction Simplified Employee Pension"; } else { System.out.println("You have chose not to participate in the retirement plan."); } } } double netPay = totalPay - itemizedDeductions; System.out.println(); System.out.println("-------------------------"); System.out.println("Payroll Details"); System.out.println("-------------------------"); System.out.println("Worker Name : " + name); System.out.println("Skill Level : " + skillLevel); System.out.println("Hours worked : " + totalHours); System.out.println("Hourly pay rate : $" + hourlyPay); System.out.println("Regular pay for 40 hours : $" + regularPay); System.out.println("Overtime pay : $" + overtimePay); System.out.println("Gross pay : $" + totalPay); if (itemizedDeductions > totalPay) { System.out.println("Error: deductions exceed total pay."); } else { System.out.println("-------------------------"); System.out.println("Deductions"); System.out.println("-------------------------"); System.out.println(insure); System.out.println(retirement); System.out.println("Total deductions : $" + itemizedDeductions); System.out.println("Net pay : $" + netPay); System.out.println("___________________________________________________"); System.out.println("___________________________________________________"); } } } }