MISY 3433-001: Java Applications in Business Lab #5 rite a program to compute an
ID: 3739172 • Letter: M
Question
MISY 3433-001: Java Applications in Business Lab #5 rite a program to compute and display the net salary of an employee, given the number of hours worked and the hourly rate. All employees are entitled to a minimum of 40 hours (if you work less than 40hours you are paid for 40hours). The rate for taxes varies depending of the gross salary as follow: Gross Salary Gross salary1000 Gross salary 1000 Taxes rate 1.5% 1.61% Your program will prompt the user to input the data from the keyboard. Hints: Analysis Input data: hourly rate, hour worked, taxes rate .Expected output: net salary Processes: o Gross salary If hours worked less than 40 then assign 40 to hours worked; . Gross salary hours worked hourly rate o Taxes If gross salary less or equal to 1000 then taxes rate is 1.5% Else taxes rate is 1.61%; o Net salary Net salary: gross salary-taxes · Implementation Create a new project called Lab5 In Lab5, implement the following two classes: 1. Employee . Attributes (similar to lab 4) . Methods Employee Tester (similar to lab 4) 2. m with the following data: Expected result Net Salary Input Number of hours (h) Hourl 81 20 $10.75 $15.45 512 $582.38 $1231.30 $472.80Explanation / Answer
You have not given your classes from Lab 1 and Lab 4, especially the Employee class. I have created a new class since I don't know what were the attributes and methods in hte previous class. You can probably copy paste the calculateSalary() method into your old code. Hope it helps.
Employee.java
==============
public class Employee {
private String name;
private int hoursWorked;
private double hourlyRate;
public Employee(String n)
{
name = n;
}
public Employee(String n, int hours, double rate)
{
name = n;
hoursWorked = hours;
hourlyRate = rate;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getHoursWorked() {
return hoursWorked;
}
public void setHoursWorked(int hoursWorked) {
this.hoursWorked = hoursWorked;
}
public double getHourlyRate() {
return hourlyRate;
}
public void setHourlyRate(double hourlyRate) {
this.hourlyRate = hourlyRate;
}
public double calculateSalary()
{
double gross, net, tax;
if(hoursWorked < 40)
hoursWorked = 40;
gross = hourlyRate * hoursWorked;
if(gross <= 1000)
tax = 1.5 * gross / 100;
else
tax = 1.61 * gross / 100;
net = gross - tax;
return net;
}
}
EmployeeTester.java
====================
import java.util.Scanner;
public class EmployeeTester {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
double hourlyRate;
int hoursWorked;
String name;
System.out.print("Enter employee name: ");
name = keyboard.nextLine();
System.out.print("Enter the no. of hours: ");
hoursWorked = keyboard.nextInt();
System.out.print("Enter the hourly rate: ");
hourlyRate = keyboard.nextDouble();
Employee e = new Employee(name, hoursWorked, hourlyRate);
System.out.printf("The net pay is $%.2f ", e.calculateSalary());
}
}
output
======
Enter employee name: John
Enter the no. of hours: 55
Enter the hourly rate: 10.75
The net pay is $582.38
--------
Enter employee name: John
Enter the no. of hours: 81
Enter the hourly rate: 15.45
The net pay is $1231.30
--------
Enter employee name: John
Enter the no. of hours: 81
Enter the hourly rate: 15.45
The net pay is $1231.30
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.