Question
Let's update our program, SalaryCalcLoop.java, from last week, to now take input about each employee from a file and write their information and salary/pay information
Let's update our program, SalaryCalcLoop.java, from last week, to now take input about each employee from a file and write their information and salary/pay information to a file.
Rashid night 60 20 Chin day 30 15 Tran day 45 10 Deeshan night 55 11.5 Serena day 24 10 Deepak day 66 12 Tyrone night 11 18 Andre night 80 15
import java.util.Scanner; import java.io.*; import java.io.FileWriter; import java.util.NoSuchElementException;
public class SalaryCalcLoop{ double pay=0, OTpay=0; void gpay(double hours, double wage){ if (hours <= 40){ pay = hours * wage; OTpay = 0; } else{ double hr, OThr; hr = 40; OThr = hours - hr; pay = hr * wage; OTpay = OThr *(wage * 1.5); } } public static void main(String[] args) throws IOException {
Scanner input = new Scanner(System.in); String name; String shifts; int shift; Double wage, hours; int sentinel = 1;
while (sentinel != 0){ System.out.println("Please enter employee name"); name = input.next(); System.out.println("Please enter the shift."); System.out.println("For the DAY shift enter 1. For the NIGHT shift enter 2."); shift = input.nextInt(); System.out.println("How many hours did the employee work this week?"); hours = input.nextDouble(); System.out.println("Please enter your hourly wage."); wage = input.nextDouble(); SalaryCalc s = new SalaryCalc(); s.gpay(hours, wage); double totalpay = s.pay + s.OTpay; System.out.println("Employee Name: "+name); System.out.println("Employee's regular pay: "+s.pay); System.out.println("Employee's overtime pay: "+s.OTpay); System.out.println("Employee's total pay: "+totalpay); if(shift == 1){ System.out.println("Employee's pay period is Friday"); } else if(shift == 2){ System.out.println("Employee's pay period is Saturday"); } System.out.println("Do you wish to enter another employee?"); System.out.println("Enter a number to continue or 0 to end"); sentinel = input.nextInt(); input.close(); } } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started