**The programming language is Java*** PART A: Write a menu-driven program that w
ID: 3853842 • Letter: #
Question
**The programming language is Java***
PART A: Write a menu-driven program that will give the user the three choices: 1) Pay Calculator, 2) Bonus Calculator, and 3) Exit.
Pay Calculator Prompt for the employee’s name and salary of an employee. Here the salary will denote an hourly wage, such as $9.25. Then ask how many hours the employee worked in the past week. Be sure to accept fractional hours. Compute the pay. Any overtime work (over 40 hours per week) is paid at 150 percent of the regular wage (1.5 the overtime pay). Print the employee’s name, hours worked, overtime hours worked (do not show overtime, if there is none), regular hours pay, overtime hours pay (do not show overtime pay if there is none), and total pay.
Bonus Calculator A company rewards salespeople for the number of sales over 5 and if the average sale is over $500. Prompt for the employee’s name, number of sales, and total sales amount. For every sale over 5 the employee is awarded $25. If the average sale is more than $500, employees are awarded 20% of the amount over $500 (e.g. the average is $750, the employee's would be awarded 20% of $250). Print the employee’s name, number of sales, . total sales amount, average sales amount, bonus on number of sales, bonus on average sale, and total bonus amount.
The exit choice will display a statement that the program will end and thank the user for using the program.
Your program should be complete and with correct convention and commenting. To obtain 50 of 100 points, your program must compile and run. You will obtain 30 points if your program runs correctly. You will obtain 20 points for all other convention and commenting (this includes file and class naming convention).
Explanation / Answer
import java.util.*;
import java.io.*;
public class TestClass {
public static Scanner sc=new Scanner(System.in);
public static String file="/home/java.txt";
public static void main(String args[]) {
while(true) {
System.out.println("1) Pay Calculator, 2) Bonus Calculator, 3) Exit.");
int x=sc.nextInt();
if(x==1) {
System.out.println("yes1");
pay_calculator();
} else if(x==2) {
System.out.println("yes2");
bonus_calculator();
} else {
break;
}
}
}
public static void pay_calculator() {
System.out.println("Enter Employee name");
String name=sc.next();
System.out.println("Enter total sales");
double sal=sc.nextDouble();
System.out.println("Enter total hours");
double hrs=sc.nextDouble();
double dwage=9.25;
double fhrs=40.5;
double overpay=0.0, overhrs=0.0, regpay=0.0, reghrs=0.0;
if(hrs>fhrs) {
regpay=fhrs*9.25;
overhrs=hrs-fhrs;
overpay=overhrs*9.25*1.5;
regpay=fhrs*9.25;
String writeto=""+name+" "+hrs+" "+overhrs+" "+regpay+" "+overpay+" "+(regpay+overpay);
System.out.println(name+" "+hrs+" "+overhrs+" "+regpay+" "+overpay+" "+(regpay+overpay));
try {
File.write(file, writeto.getBytes(), StandardOpenOption.APPEND);
} catch (IOException e) {
}
} else {
regpay=hrs*9.25;
String writeto=""+name+" "+hrs+" "+regpay+" "+regpay;
System.out.println(name+" "+hrs+" "+regpay+" "+regpay);
try {
File.write(file, writeto.getBytes(), StandardOpenOption.APPEND);
} catch (IOException e) {
}
}
}
public static void bonus_calculator() {
System.out.println("Enter Employee name");
String name=sc.next();
System.out.println("Enter total sales");
int scount=sc.nextInt();
System.out.println("Enter total amount");
double totalamt=sc.nextDouble();
int salediff=0;
double avgamt=totalamt/scount;
double bonussale=0.0, bonusavg=0.0;
if(scount>5) {
salediff=scount-5;
bonussale=salediff*25;
}
if(avgamt>500) {
bonusavg=(avgamt-500);
bonusavg+=(bonusavg*20)/100;
}
String writeto=""+name+" "+scount+" "+totalamt+" "+avgamt+" "+bonussale+" "+bonusavg+" "+(bonussale+bonusavg);
try {
File.write(file, writeto.getBytes(), StandardOpenOption.APPEND);
} catch (IOException e) {
}
System.out.println(name+" "+scount+" "+totalamt+" "+avgamt+" "+bonussale+" "+bonusavg+" "+(bonussale+bonusavg));
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.