Untitled
unknown
plain_text
4 years ago
3.7 kB
5
Indexable
import java.util.Scanner;
public class Pay {
public static void main(String[] args) {
double hourlyPay = 0.00;
Scanner input = new Scanner(System.in);
System.out.println("Enter 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 this week?");
double regularHours = input.nextDouble();
double overtimeHours = 0.00;
if (regularHours > 40.00) {
overtimeHours = regularHours - 40.00;
regularHours = 40.00;
}
double regularPay = regularHours * hourlyPay;
double overtimePay = overtimeHours * hourlyPay * 1.5;
double totalHours = regularHours + overtimeHours;
double totalPay = regularPay + overtimePay;
final double medicalInsurance = 32.50;
final double dentalInsurance = 20.00;
final double longtermDisability = 10.00;
double retirementPlan = totalPay * 0.03;
double itemizedDeductions = 0;
int choice = 0;
int numSelections = 0;
if (skillLevel == 2 || skillLevel == 3) {
do {
System.out.println(
"Would you like:\n1) medical insurance \n2) dental insurance \n3) long term disability insurance? \nEnter 0 to decline any coverages when prompted.");
choice = input.nextInt();
numSelections++;
if (choice == 1) {
itemizedDeductions += medicalInsurance;
System.out.println("Medical insurance coverage selected.\n");
} else if (choice == 2) {
itemizedDeductions += dentalInsurance;
System.out.println("Dental insurance coverage seleceted.\n");
} else if (choice == 3) {
itemizedDeductions += longtermDisability;
System.out.println("Long term disability insurance coverage selected.\n");
} else {
System.out.println("You have elected to opt out of insurance coverage.\n");
choice = 0;
}
} while (choice != 0 && numSelections < 3);
}
if (skillLevel == 3) {
System.out.println(
"Congratulations you qualify for our retirement plan! \nDo you want to participate 1) Yes 2) No");
double retirementChoice = input.nextDouble();
if (retirementChoice == 1) {
itemizedDeductions += retirementPlan;
System.out.println("You are now enrolled in our retirement plan.\n");
} else {
System.out.println("You have elected to opt out of the retirement plan.\n");
}
}
double grossPay = totalPay;
double netPay = totalPay - itemizedDeductions;
System.out.println();
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("Total pay: $" + totalPay);
System.out.println("Total deductions: $" + itemizedDeductions);
if (itemizedDeductions > totalPay) {
System.out.println("Error: deductions exceed total pay.");
} else {
System.out.println("Net pay: $" + netPay);
}
}
}
}Editor is loading...