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

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 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...
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....
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
write a C++ program to CREATE A CLASS EMPLOYEE WITH YOUR CHOICE OF ATTRIBUTES AND FUNCTIONS...
write a C++ program to CREATE A CLASS EMPLOYEE WITH YOUR CHOICE OF ATTRIBUTES AND FUNCTIONS COVERING THE FOLLOWING POINTS: 1) COUNTING NUMBER OF OBJECTS CREATED ( NO OBJECT ARRAY TO BE USED) USING ROLE OF STATIC MEMBER 2) SHOWING THE VALID INVALID STATEMENTS IN CASE OF STATIC MEMBER WITH NON STATIC MEMBER FUNCTION, NON STATIC MEMBERS OF CLASS WITH STATIC MEMBER FUNCTION, BOTH STATIC. SHOW THE ERRORS WHERE STATEMENTS ARE INVALID. 3) CALL OF STATIC MEMBER FUNCTION, DECLARATION OF...
Implement a class Student, including the following attributes and methods: Two public attributes name(String) and score...
Implement a class Student, including the following attributes and methods: Two public attributes name(String) and score (int). A constructor expects a name as a parameter. A method getLevel to get the level(char) of the student. score level table: A: score >= 90 B: score >= 80 and < 90 C: score >= 60 and < 80 D: score < 60 Example:          Student student = new Student("Zack"); student.score = 10; student.getLevel(); // should be 'D'. student.score = 60; student.getLevel(); //...
In C++ Demonstrate inheritance. Create an Airplane class with the following attributes: • manufacturer : string...
In C++ Demonstrate inheritance. Create an Airplane class with the following attributes: • manufacturer : string • speed : float Create a FigherPlane class that inherits from the Airplane class and adds the following attributes: • numberOfMissiles : short
In Java, Here is a basic Name class. class Name { private String first; private String...
In Java, Here is a basic Name class. class Name { private String first; private String last; public Name(String first, String last) { this.first = first; this.last = last; } public boolean equals(Name other) { return this.first.equals(other.first) && this.last.equals(other.last); } } Assume we have a program (in another file) that uses this class. As part of the program, we need to write a method with the following header: public static boolean exists(Name[] names, int numNames, Name name) The goal of...
in Java, Create a class called EMPLOYEE that includes three instance variables – a first name...
in Java, Create a class called EMPLOYEE that includes three instance variables – a first name (type String), a last name (type String) and a monthly salary (double). Provide a constructor that initializes the three instance variables. Provide a set and a get method for each instance variable. If the monthly salary is not positive, do not set its value. Write a test app names EmployeeTest that demonstrates class EMLOYEE’s capabilities. Create two EMPLOYEE objects and display each object’s yearly...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT