Question

In: Computer Science

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

Create an abstract 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 an abstract method called earnings. Create another class HourlyEmployee that inherits from the abstract Employee class. HourEmployee must use the inherited parent class variables and add in attributes 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. Implement the Employee abstract earnings method in 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.

SUBMIT YOUR JAVA CODE AND PSUEDOCODE

Solutions

Expert Solution

import java.util.*;
abstract class Employee
{
public String firstName,lastName,employeeID,address,city,state;
public Employee(String firstName,String lastName,String employeeID,String address,String city,String state)
{
this.firstName=firstName;
this.lastName=lastName;
this.employeeID=employeeID;
this.address=address;
this.city=city;
this.state=state;
}
abstract double earnings();
}
class HourlyEmployee extends Employee
{
double HourlyRate,HoursWorked;
public HourlyEmployee(String firstName,String lastName,String employeeID,String address,String city,String state,double HourlyRate,double HoursWorked)
{
super(firstName,lastName,employeeID,address,city,state);
this.HourlyRate=HourlyRate;
this.HoursWorked=HoursWorked;
}
public double earnings()
{
return HourlyRate*HoursWorked;
}
}

public class Main
{
   public static void main(String[] args)
   {
       Scanner s = new Scanner(System.in);
       String firstName,lastName,employeeID,address,city,state;
       double HourlyRate,HoursWorked;
       System.out.print("Enter the first name: ");
       firstName=s.nextLine();
       System.out.print("Enter the last name: ");
       lastName=s.nextLine();
       System.out.print("Enter the employee id: ");
       employeeID=s.nextLine();
       System.out.print("Enter the address: ");
       address=s.nextLine();
       System.out.print("Enter the city: ");
       city=s.nextLine();
       System.out.print("Enter the state: ");
       state=s.nextLine();
       System.out.print("Enter the hourly rate: ");
       HourlyRate=s.nextDouble();
       System.out.print("Enter the hours worked: ");
       HoursWorked=s.nextDouble();      
       HourlyEmployee e1 = new HourlyEmployee(firstName,lastName,employeeID,address,city,state,HourlyRate,HoursWorked);
       System.out.println("Earnings : "+e1.earnings());
       System.out.print("Enter the first name: ");
       s.nextLine();
       firstName=s.nextLine();
       System.out.print("Enter the last name: ");
       lastName=s.nextLine();
       System.out.print("Enter the employee id: ");
       employeeID=s.nextLine();
       System.out.print("Enter the address: ");
       address=s.nextLine();
       System.out.print("Enter the city: ");
       city=s.nextLine();
       System.out.print("Enter the state: ");
       state=s.nextLine();
       System.out.print("Enter the hourly rate: ");
       HourlyRate=s.nextDouble();
       System.out.print("Enter the hours worked: ");
       HoursWorked=s.nextDouble();
       HourlyEmployee e2 = new HourlyEmployee(firstName,lastName,employeeID,address,city,state,HourlyRate,HoursWorked);
       System.out.println("Earnings : "+e2.earnings());  
   }
}



Related Solutions

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...
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...
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...
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...
Part I: The Employee Class You are to first update the Employee class to include two virtual functions. This will make the Employee class an abstract class.
  Part I:   The Employee Class You are to first update the Employee class to include two virtual functions. This will make the Employee class an abstract class. * Update the function display() to be a virtual function     * Add function, double weeklyEarning() to be a pure virtual function. This will make Employee an abstract class, so your main will not be able to create any Employee objects. Part II: The Derived Classes Add an weeklyEarning() function to each...
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....
Java Create an abstract Product Class Add the following private attributes: name sku (int) price (double)...
Java Create an abstract Product Class Add the following private attributes: name sku (int) price (double) Create getter/setter methods for all attributes Create a constructor that takes in all attributes and sets them Remove the default constructor Override the toString() method and return a String that represents the building object that is formatted nicely and contains all information (attributes) Create a FoodProduct Class that extends Product Add the following private attributes: expDate (java.util.Date) for expiration date refrigerationTemp (int) if 70...
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...
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(); //...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT