Question

In: Computer Science

Create a class Employee. Your Employee class should include the following attributes: First name (string) Last...

Create a class Employee. Your Employee class should include the following attributes:

First name (string)

Last name (string)

Employee id (string)

Employee home street address (string)

Employee home city (string)

Employee home state (string)

Write a constructor to initialize the above Employee attributes.

Create another class HourlyEmployee that inherits from the Employee class.   HourEmployee must use the inherited parent class variables and add in HourlyRate and HoursWorked. Your HourEmployee class should contain a constructor that calls the constructor from the Employee class to initialize the common instance variables but also initializes the HourlyRate and HoursWorked. Add an earnings method to HourlyEmployee to calculate the earnings for a week. Note that earnings is hourly rate * hours worked.

Create a test class that prompts the user for the information for two hourly employees, creates the 2 two hourly employees objects, calls the earnings method then displays the attributes and earnings for each of the two hourly.

Solutions

Expert Solution

import java.util.Scanner;

class Employee {
   private String firstName;
   private String lastName;
   private String id;
   private String street;
   private String city;
   private String state;

   public Employee() {
   }

   public Employee(String aFirstName, String aLastName, String aId, String aStreet, String aCity, String aState) {
       super();
       firstName = aFirstName;
       lastName = aLastName;
       id = aId;
       street = aStreet;
       city = aCity;
       state = aState;
   }

   public String getFirstName() {
       return firstName;
   }

   public void setFirstName(String aFirstName) {
       firstName = aFirstName;
   }

   public String getLastName() {
       return lastName;
   }

   public void setLastName(String aLastName) {
       lastName = aLastName;
   }

   public String getId() {
       return id;
   }

   public void setId(String aId) {
       id = aId;
   }

   public String getStreet() {
       return street;
   }

   public void setStreet(String aStreet) {
       street = aStreet;
   }

   public String getCity() {
       return city;
   }

   public void setCity(String aCity) {
       city = aCity;
   }

   public String getState() {
       return state;
   }

   public void setState(String aState) {
       state = aState;
   }

   @Override
   public String toString() {
       return "FirstName : " + firstName + "\nLastName : " + lastName + "\nId : " + id + "\nStreet : " + street
               + "\nCity : " + city + "\nState : " + state;
   }

}

class HourlyEmployee extends Employee {
   int hoursWorked;
   double hourRate;

   public HourlyEmployee() {

   }

   public HourlyEmployee(String aFirstName, String aLastName, String aId, String aStreet, String aCity, String aState,
           int aHoursWorked, double aHourRate) {
       super(aFirstName, aLastName, aId, aStreet, aCity, aState);
       hoursWorked = aHoursWorked;
       hourRate = aHourRate;
   }

   // returns earnings for that employee
   public double earnings() {
       return hourRate * hoursWorked;
   }

   public int getHoursWorked() {
       return hoursWorked;
   }

   public void setHoursWorked(int aHoursWorked) {
       hoursWorked = aHoursWorked;
   }

   public double getHourRate() {
       return hourRate;
   }

   public void setHourRate(double aHourRate) {
       hourRate = aHourRate;
   }

   public String toString() {
       return super.toString() + "\nHours Worked : " + hoursWorked + "\nPay Rate : " + hourRate + "\nEarnings : "
               + earnings();
   }
}

public class TestEmp {
   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       System.out.println("Enter emp1 first name");
       String fname = sc.nextLine();
       System.out.println("Enter emp1 last name");
       String lname = sc.nextLine();

       System.out.println("Enter emp1 Id");
       String id = sc.nextLine();

       System.out.println("Enter emp1 street");
       String street = sc.nextLine();
       System.out.println("Enter emp1 City");
       String city = sc.nextLine();
       System.out.println("Enter emp1 state");
       String state = sc.nextLine();

       System.out.println("Enter Emp1 hours and hour rate");
       int hours = sc.nextInt();
       double rate = sc.nextDouble();
       HourlyEmployee h1 = new HourlyEmployee(fname, lname, id, street, city, state, hours, rate);
       System.out.println("Enter emp2 first name");
       fname = sc.nextLine();
       fname = sc.nextLine();
       System.out.println("Enter emp2 last name");
       lname = sc.nextLine();

       System.out.println("Enter emp2 Id");
       id = sc.nextLine();

       System.out.println("Enter emp2 street");
       street = sc.nextLine();
       System.out.println("Enter emp2 City");
       city = sc.nextLine();
       System.out.println("Enter emp2 state");
       state = sc.nextLine();
       System.out.println("Enter emp2 hours and hour rate");
       hours = sc.nextInt();
       rate = sc.nextDouble();
       sc.close();
       HourlyEmployee h2 = new HourlyEmployee(fname, lname, id, street, city, state, hours, rate);
       System.out.println("Employee 1 earnings : " + h1);
       System.out.println("Employee 2 earnings : " + h2);

   }
}

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me


Related Solutions

Create a class Client. Your Client class should include the following attributes: Company Name (string) Company...
Create a class Client. Your Client class should include the following attributes: Company Name (string) Company id (string) Billing address (string) Billing city (string) Billing state (string) Write a constructor to initialize the above Employee attributes. Create another class HourlyClient that inherits from the Client class.   HourClient must use the inherited parent class variables and add in hourlyRate and hoursBilled. Your Hourly Client class should contain a constructor that calls the constructor from the Client class to initialize the common...
Specifications Create an abstract Employee class that provides private attributes for the first name, last name,...
Specifications Create an abstract Employee class that provides private attributes for the first name, last name, email address, and social security number. This class should provide functions that set and return the employee’s first name, last name, email address, and social security number. This class has a function: get_net_income which returns 0. Create a Manager class that inherits the Employee class. This class should add private attributes for years of experience and the annual salary. This class should also provide...
Using JAVA Create a class Client. Your Client class should include the following attributes: Company Name...
Using JAVA Create a class Client. Your Client class should include the following attributes: Company Name (string) Company id (string) Billing address (string) Billing city (string) Billing state (string) Write a constructor to initialize the above Employee attributes. Create another class HourlyClient that inherits from the Client class.   HourClient must use the inherited parent class variables and add in hourlyRate and hoursBilled. Your Hourly Client class should contain a constructor that calls the constructor from the Client class to initialize...
JAVA Program Create a class called SoccerPlayer Create 4 private attributes: First Name, Last Name, Games,...
JAVA Program Create a class called SoccerPlayer Create 4 private attributes: First Name, Last Name, Games, and Goals Have two constructors Constructor 1 – default constructor; all values to "NONE" or zero Constructor 2 – accepts input of first name, last name, games and goals. Create get and set methods for each of the four attributes Create a method the returns a double that calculates the average goals per game This method checks for zero games played: If there are...
JAVA PROGRAMMING Part 1 Create a class Student, with attributes id, first name, last name. (All...
JAVA PROGRAMMING Part 1 Create a class Student, with attributes id, first name, last name. (All the attributes must be String) Create a constructor that accepts first name and last name to create a student object. Create appropriate getters and setters Create another class StudentOperationClient, that contains a main program. This is the place where the student objects are created and other activities are performed. In the main program, create student objects, with the following first and last names. Chris...
C# (Thank you in advance) Create an Employee class with five fields: first name, last name,...
C# (Thank you in advance) 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...
Please Code Using Java Create a class called SoccerPlayer Create 4 private attributes: First Name, Last...
Please Code Using Java Create a class called SoccerPlayer Create 4 private attributes: First Name, Last Name, Games, and Goals Have two constructors Constructor 1 – default constructor; all values to "NONE" or zero Constructor 2 – accepts input of first name, last name, games and goals. Create get and set methods for each of the four attributes Create a method the returns a double that calculates the average goals per game This method checks for zero games played: If...
Write a class named Person with data attributes for a person’s first name, last name, and...
Write a class named Person with data attributes for a person’s first name, last name, and telephone number. Next, write a class named Customer that is a subclass of the Person class. The Customer class should have a data attribute for a customer number and a Boolean data attribute indicating whether the customer wishes to be on a calling list. Demonstrate an instance of the Customer class in a simple program. Using python
with PHP Create a class called Employee that includes three instance variables—a first name (type String),...
with PHP Create a class called Employee that includes three instance variables—a first name (type String), a last name (type String) and a monthly salary int). Provide a constructor that initializes the three instance data member. Provide a set and a get method for each instance variable. If the monthly salary is not positive, do not set its 0. Write a test app named EmployeeTest that demonstrates class Employee’s capabilities. Create two Employee objects and display each object’s yearly salary....
you will find a class called Employee. This class should include a constructor that sets name...
you will find a class called Employee. This class should include a constructor that sets name to blanks and salary to $0.00 and a constructor which sets name to a starting name and salary to a set amount. Additionally, the class should include methods to set the name and salary and return the name and salary. Create another method to return the name and salary nicely formatted as a string (hint – research the toString method). You will create a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT