Question

In: Computer Science

Design a class named Employee. The class should keep the following information in fields: ·         Employee...

Design a class named Employee. The class should keep the following information in fields:

·         Employee name

·         Employee number in the format XXX–L, where each X is a digit within the range 0–9 and the L is a letter within the range A–M.

·         Hire date

Write one or more constructors and the appropriate accessor and mutator methods for the class. Next, write a class named ProductionWorker that inherits from the Employee class. The ProductionWorker class should have fields to hold the following information:

·         Shift (an integer)

·         Hourly pay rate (a double)

·         Add hours and calculate pay

The workday is divided into two shifts: day and night. The shift field will be an integer value representing the shift that the employee works. The day shift is shift 1 and the night shift is shift 2. Write one or more constructors and the appropriate accessor and mutator methods for the class. Demonstrate the classes by writing a program that uses a ProductionWorker object.

Solutions

Expert Solution

Employee.java

public class Employee {

   // Declaring instance variables
   private String employee_name;
   private String employee_no;
   private String hiredate;

   // Default Constructor
   public Employee() {
   }

   // Parameterized Constructor
   public Employee(String employee_name, String employee_no, String hiredate) {
       this.employee_name = employee_name;
       this.employee_no = employee_no;
       this.hiredate = hiredate;
   }

   // Setters and Getters
   public String getEmployee_name() {
       return employee_name;
   }

   public void setEmployee_name(String employee_name) {
       this.employee_name = employee_name;
   }

   public String getEmployee_no() {
       return employee_no;
   }

   public void setEmployee_no(String employee_no) {
       this.employee_no = employee_no;
   }

   public String getHiredate() {
       return hiredate;
   }

   public void setHiredate(String hiredate) {
       this.hiredate = hiredate;
   }

   // toString() method which displays the contents of an Object inside it.
   @Override
   public String toString() {
       System.out.println("Employee Name =" + employee_name);
       System.out.println("Employee No =" + employee_no);
       System.out.println("Hiredate =" + hiredate);
       return "";
   }

}

___________________

ProductionWorker.java

public class ProductionWorker extends Employee {
   // Declaring instance variables
   private double hourly_pay_rate;
   private int shift;
   private int no_of_hours;

   // Default Constructor
   public ProductionWorker() {
       super();
   }

   // Parameterized Constructor
   public ProductionWorker(String employee_name, String employee_no,
           String hiredate, double hourly_pay_rate, int shift) {
       super(employee_name, employee_no, hiredate);
       this.hourly_pay_rate = hourly_pay_rate;
       this.shift = shift;

   }

   // Setters and Getters
   public double getHourly_pay_rate() {
       return hourly_pay_rate;
   }

   public void setHourly_pay_rate(double hourly_pay_rate) {
       this.hourly_pay_rate = hourly_pay_rate;
   }

   public int getShift() {
       return shift;
   }

   public void setShift(int shift) {
       this.shift = shift;
   }
  
   public void addHours(int hours)
   {
       this.no_of_hours+=hours;
   }
  
   public double calculate_Pay()
   {
       return no_of_hours*hourly_pay_rate;
   }

   // toString() method which displays the contents of an Object inside it.
   @Override
   public String toString() {
       super.toString();
       System.out.println("Hourly Pay Rate =" + hourly_pay_rate);
       if(getShift()==1)
       System.out.println("Shift = Day");
       else if(getShift()==2)
       System.out.println("Shift = Night");  
       return "";
   }

}

___________________

Driver.java

public class Driver {

   public static void main(String[] args) {
  
      
   //Creating the Production Worker Object by passing the parameters  
ProductionWorker pw1=new ProductionWorker("Williams","123-B","31-Dec-2014", 10, 1);
  
//Displaying the Production worker details
System.out.println("===== Production Worker Details =====");
pw1.toString();
pw1.addHours(39);
System.out.println("Payment for Production Worker 1:$"+pw1.calculate_Pay());
  
   //Creating the Production Worker Object by passing the parameters  
ProductionWorker pw2=new ProductionWorker("Pitersen","345-H","11-Feb-2006", 15, 2);
  
//Displaying the Production worker details
System.out.println("===== Production Worker Details =====");
pw2.toString();
pw2.addHours(35);
System.out.println("Payment for Production Worker 2: $"+pw2.calculate_Pay());


   }

}

_____________________

Output:

===== Production Worker Details =====
Employee Name =Williams
Employee No =123-B
Hiredate =31-Dec-2014
Hourly Pay Rate =10.0
Shift = Day
Payment for Production Worker 1:$390.0
===== Production Worker Details =====
Employee Name =Pitersen
Employee No =345-H
Hiredate =11-Feb-2006
Hourly Pay Rate =15.0
Shift = Night
Payment for Production Worker 2: $525.0

____________Thank You


Related Solutions

Design a class named Employee. The class should keep the following information in fields: ·         Employee...
Design a class named Employee. The class should keep the following information in fields: ·         Employee name ·         Employee number in the format XXX–L, where each X is a digit within the range 0–9 and the L is a letter within the range A–M. ·         Hire date Write one or more constructors and the appropriate accessor and mutator methods for the class. Next, write a class named ProductionWorker that inherits from the Employee class. The ProductionWorker class should have fields...
Design a class named Pet, which should have the following fields: Name – The name field...
Design a class named Pet, which should have the following fields: Name – The name field holds the name of a pet. Type – The type field holds the type of animal that is the pet. Example values are “Dog”, “Cat”, and “Bird”. Age – The age field holds the pet’s age. The Pet class should also have the following methods: setName – The setName method stores a value in the name field. setType – The setType method stores a...
In java, design a class named Motorcycle that has the following fields: • year – The...
In java, design a class named Motorcycle that has the following fields: • year – The year field is an int that holds the motorcycle’s year • make – The make field references a String object that holds the make of the motorcycle. • speed – The speed field is an int that holds the motorcycle’s current speed The class should have the following constructor and other methods: • Constructor – the constructor should accept the motorcycle’s year and make...
Complete the following C++ tasks: a. Design a class named BaseballGame that has fields for two...
Complete the following C++ tasks: a. Design a class named BaseballGame that has fields for two team names and a final score for each team. Include methods to set and get the values for each data field. Create the class diagram and write the pseudocode that defines the class. b. Design an application that declares three BaseballGame objects and sets and displays their values. c. Design an application that declares an array of 12 BaseballGame objects. Prompt the user for...
Write a C++ program (The Account Class) Design a class named Account that contains (keep the...
Write a C++ program (The Account Class) Design a class named Account that contains (keep the data fields private): a) An int data field named id for the account. b) A double data field named balance for the account. c) A double data field named annualInterestRate that stores the current interest rate. d) A no-arg constructor that creates a default account with id 0, balance 0, and annualInterestRate 0. e) The accessor and mutator functions for id, balance, and annualInterestRate....
Problem Statement Design a class named Car that has the following fields: year: The year field...
Problem Statement Design a class named Car that has the following fields: year: The year field is an integer that holds the car’s year. make: the make field is a String that holds the make of the car. speed: the speed field is an integer that holds the car’s current speed. In addition, the class should have the following constructor and other methods: Constructor: the constructor should accept the car’s year >model and make as parameters. These values should be...
Using c++ Design a system to keep track of employee data. The system should keep track...
Using c++ Design a system to keep track of employee data. The system should keep track of an employee’s name, ID number and hourly pay rate in a class called Employee. You may also store any additional data you may need, (hint: you need something extra). This data is stored in a file (user selectable) with the id number, hourly pay rate, and the employee’s full name (example): 17 5.25 Daniel Katz 18 6.75 John F. Jones Start your main...
(Java) Design a class named Person with fields for holding a person’s name, address, and telephone...
(Java) Design a class named Person with fields for holding a person’s name, address, and telephone number. Write one or more constructors and the appropriate mutator and accessor methods for the class’s fields. Next, design a class named Customer, which extends the Person class. The Customer class should have a field for a customer number and a boolean field indicating whether the customer wishes to be on a mailing list. Write one or more constructors and the appropriate mutator and...
Create a class named “Car” which has the following fields. The fields correspond to the columns...
Create a class named “Car” which has the following fields. The fields correspond to the columns in the text file except the last one. i. Vehicle_Name : String ii. Engine_Number : String iii. Vehicle_Price : double iv. Profit : double v. Total_Price : double (Total_Price = Vehicle_Price + Vehicle_Price* Profit/100) 2. Write a Java program to read the content of the text file. Each row has the attributes of one Car Object (except Total_Price). 3. After reading the instances of...
Java Question Design a class named Person and its two subclasses named Student and Employee. Make...
Java Question Design a class named Person and its two subclasses named Student and Employee. Make Faculty and Staff subclasses of Employee. A person has a name, address, phone number, and email address. A student has a class status (freshman, sophomore, junior, or senior). Define the status as a constant. An employee has an office, salary, and date hired. Use the Date class to create an object for date hired. A faculty member has office hours and a rank. A...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT