Question

Define a class named Employee that has four data fields: name: String hoursWorked: double hourlyPayrate: double...

Define a class named Employee that has four data fields:
name: String

hoursWorked: double

hourlyPayrate: double

bonusRate: double

The class has two constructors:
1. constructor without arguments: initialize name to empty string, and all other data fields to 0.0
2. constructor with a String type arguments and three double type arguments. Use them to initialize the data fields properly

The class also has:

1. Getter method for each data field to return the value of the data field

2. Setter method for each data field to set a new value of that data field

3. A method called calculateRegularPay to calculate and return the regular salary using the following formula:

regular salary of an employee = hoursWorked * hourlyPayRate

4. A method called calculateBonus to calculate and return the amount of bonus using the following formula:

bonus amount of an employee = regular salary of an employee * bonus rate

where the regular salary of an employee is the return value of the method in 3

5. A method called calculateGrossPay to calculate and return the gross pay using the following formula:

gross pay of an employee = regular salary of an employee + bonus amount of the employee

where the regular salary of an employee is the return value of the method in 3 and the bonus amount is the return value of the method in 4

Then write a separate demo program to:

create an empty employee. Call the setters methods of the object to set values for all data fields. Call the three calculate methods to calculate regular pay, bonus amount, and gross pay for the employee. Display results.

Homework Answers

Answer #1

If you have any doubts, please give me comment...

class Employee{

private String name;

private double hoursWorked;

private double hourlyPayrate;

private double bonusRate;

public Employee(){

name = "";

hoursWorked = 0.0;

hourlyPayrate = 0.0;

bonusRate = 0.0;

}

public Employee(String name, double hoursWorked, double hourlyPayrate, double bonusRate){

this.name = name;

this.hoursWorked = hoursWorked;

this.hourlyPayrate = hourlyPayrate;

this.bonusRate = bonusRate;

}

/**

* @param name the name to set

*/

public void setName(String name) {

this.name = name;

}

/**

* @param hoursWorked the hoursWorked to set

*/

public void setHoursWorked(double hoursWorked) {

this.hoursWorked = hoursWorked;

}

/**

* @param hourlyPayrate the hourlyPayrate to set

*/

public void setHourlyPayrate(double hourlyPayrate) {

this.hourlyPayrate = hourlyPayrate;

}

/**

* @param bonusRate the bonusRate to set

*/

public void setBonusRate(double bonusRate) {

this.bonusRate = bonusRate;

}

/**

* @return the name

*/

public String getName() {

return name;

}

/**

* @return the hoursWorked

*/

public double getHoursWorked() {

return hoursWorked;

}

/**

* @return the hourlyPayrate

*/

public double getHourlyPayrate() {

return hourlyPayrate;

}

/**

* @return the bonusRate

*/

public double getBonusRate() {

return bonusRate;

}

public double calculateRegularPay(){

return hoursWorked * hourlyPayrate;

}

public double calculateBonus(){

return calculateRegularPay() * (bonusRate/100);

}

public double calculateGrossPay(){

return calculateRegularPay()+calculateBonus();

}

}

public class EmployeeDemo{

public static void main(String[] args) {

Employee employee = new Employee();

employee.setName("ANUNAGA");

employee.setHoursWorked(30);

employee.setHourlyPayrate(25);

employee.setBonusRate(5);

double regularPay = employee.calculateRegularPay();

double bonusPay = employee.calculateBonus();

double grossPay = employee.calculateGrossPay();

System.out.println("Regular Pay: "+regularPay);

System.out.println("Bonus Pay: "+bonusPay);

System.out.println("Gross Pay: "+grossPay);

}

}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Create a class called Employee that contains three instance variables (First Name (String), Last Name (String),...
Create a class called Employee that contains three instance variables (First Name (String), Last Name (String), Monthly Salary (double)). Create a constructor that initializes these variables. Define set and get methods for each variable. If the monthly salary is not positive, do not set the salary. Create a separate test class called EmployeeTest that will use the Employee class. By running this class, create two employees (Employee object) and print the annual salary of each employee (object). Then set the...
Q:Could you fill in the blank。 class Employee{ // field private String name; private (1) _float__...
Q:Could you fill in the blank。 class Employee{ // field private String name; private (1) _float__ salary; // constructor (2) ________________________________________ // method public (3) __String____ getName( ){ return name; } public float getSalary( ){ return Salary; } public (4) ________ compare( (5) _________________ { (6) ____________________________________ } }// class Employee public class EmployeeUI{ public static void main(String[ ] args){ Employee e1 = new Employee(“William”); Employee e2 = new Employee(“Rchard”); if(Employee.compare(e1, e2)) System.out.println(“same employee”); else System.out.println(“different employee”); } }//class EmployeeUI
Using Inheritance Consider the following (base) class. class Employee(object): def __init__(self, name, salary): self._name = name...
Using Inheritance Consider the following (base) class. class Employee(object): def __init__(self, name, salary): self._name = name self._salary = salary def my_name(self): return self._name def wage(self): return self._salary/26 # fortnight pay Define a new subclass of Employee called Worker. A worker has a manager, who is another employee; their manager is given as an argument to the constructor. You should define a method get_manager that returns the worker’s manager. boss = Employee('Mr. Burns', 1000000) worker = Worker('Waylon Smithers', 2500, boss) Define...
Haviing trouble with my homework (java) 1)Write the class CustomerAccount, which has fields/attributes called custID of...
Haviing trouble with my homework (java) 1)Write the class CustomerAccount, which has fields/attributes called custID of type String, custName of type String and checkingBalance of type double and savingBalance of type double 2)Write the constructor for CustomerAccount class. The constructor takes parameters to initialize custID, custName, checkingBalance and savingBalance. 3)Write the mutator method for all attributes of the class CustomerAccount. then Write the toString method for class CustomerAccount.
JAVA Write a Student class with a String name and double gpa class members. Write a...
JAVA Write a Student class with a String name and double gpa class members. Write a constructor, get and set methods, and a toString method.
Create a class called Employee that should include four pieces of information as instance variables—a firstName...
Create a class called Employee that should include four pieces of information as instance variables—a firstName (type String), a lastName (type String), a mobileNumber (type String) and a salary (type int). Your class (Employee) should have a full argument constructor that initializes the four instance variables. Provide a set and a get method for each instance variable. The validation for each attribute should be like below: mobileNumber should be started from “05” and the length will be limited to 10...
Using C# Create an Employee class with five fields: first name, last name, workID, yearStartedWked, and...
Using C# Create an Employee class with five fields: first name, last name, workID, yearStartedWked, and initSalary. It includes constructor(s) and properties to initialize values for all fields. Create an interface, SalaryCalculate, class that includes two functions: first,CalcYearWorked() function, it takes one parameter (currentyear) and calculates the number of year the worker has been working. The second function, CalcCurSalary() function that calculates the current year salary. Create a Worker classes that is derived from Employee and SalaryCalculate class. In Worker...
public class Bicycle { // Instance variables (fields) private String ownerName; private int licenseNumber; // Constructor...
public class Bicycle { // Instance variables (fields) private String ownerName; private int licenseNumber; // Constructor public Bicycle( String name, int license ) { ownerName = name;    licenseNumber = license; } // Returns the name of the bicycle's owner public String getOwnerName( ) { return ownerName; } // Assigns the name of the bicycle's owner public void setOwnerName( String name ) { ownerName = name; } // Returns the license number of the bicycle public int getLicenseNumber( ) {...
In this assignment, you will be building upon the work that you did in Lab #5A...
In this assignment, you will be building upon the work that you did in Lab #5A by expanding the original classes that you implemented to represent circles and simple polygons. Assuming that you have completed Lab #5A (and do not move on to this assignment unless you have!), copy your Circle, Rectangle, and Triangle classes from that assignment into a new NetBeans project, then make the following changes: Create a new Point class containing X and Y coordinates as its...
Write a class called Item that has a string field called name and a double field...
Write a class called Item that has a string field called name and a double field called price and an integer field called quantity. In main, create a bag of type Item and place several item objects in the bag. Then in main calculate the total price of items purchased. You may remove each item and add the price to a total variable in a loop. The loop should end when the bag is empty. Java
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT