Question

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

JAVA HELP

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 then, Write one or more constructors and the appropriate accessor and mutator methods for the class. Next, write a class named ProductionWorker that extends the Employee class. The ProductionWorker class should have fields to hold the following information: Shift (an integer) Hourly pay rate (a double) 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. Added specs: All constructors should initialize all class fields all methods and properties are commented the only print method permitted is printf

0 0
Add a comment Improve this question Transcribed image text
Answer #1

public class Employee {
  
   //class member variables
   String empName;
   String empNumber;
   String hireDate;
  
   //getters and setters
   public String getEmpName() {
       return empName;
   }
   public void setEmpName(String empName) {
       this.empName = empName;
   }
   public String getEmpNumber() {
       return empNumber;
   }
   public void setEmpNumber(String empNumber) {
       this.empNumber = empNumber;
   }
   public String getHireDate() {
       return hireDate;
   }
   public void setHireDate(String hireDate) {
       this.hireDate = hireDate;
   }
  
   //default constructor
   public Employee() {
       setEmpName("NO NAME PROVIDED");
       setEmpNumber("NO EMP NUMBER PROVIDED");
       setHireDate("NO HIRE DATE PROVIDED");
   }
  
   //paramterized constructor
   public Employee(String empName, String empNumber, String hireDate) {
       setEmpName(empName);
       setEmpNumber(empNumber);
       setHireDate(hireDate);
   }
}

public class ProductionWorker extends Employee{
  
   //class member variables

   int shift;
   double hourlyPay;
  
   //getters and setters
   public int getShift() {
       return shift;
   }
   public void setShift(int shift) {
       this.shift = shift;
   }
   public double getHourlyPay() {
       return hourlyPay;
   }
   public void setHourlyPay(double hourlyPay) {
       this.hourlyPay = hourlyPay;
   }
  
  
   //default constructor
   public ProductionWorker(){
       super();
       setHourlyPay(0);
       setShift(0);
   }
  
   //paramterized constructor
   public ProductionWorker(String empName, String empNumber, String hireDate, int shift, double hourlyPay) {
       super(empName, empNumber, hireDate);
       setShift(shift);
       setHourlyPay(hourlyPay);
   }
  
   //method toString that returns a string containing info. about the object
   public String toString() {
       String res = "Name: " + getEmpName() + "\n";
       res += "Emp Number: " + getEmpNumber() + "\n";
       res += "Hire Date: " + getHireDate() + "\n";
       if(getShift() == 0) {
           res += "Shift: Morning\n";
       } else {
           res += "Shift: Evening\n";
       }
       res += "Hourly pay: " + getHourlyPay();
      
       return res;
   }
}

public class TestProductionWorker {

   public static void main(String[] args) {
       // TODO Auto-generated method stub
       ProductionWorker pw_default = new ProductionWorker();
       ProductionWorker pw_paramter = new ProductionWorker("Shashank", "123-A", "21-10-2019", 1, 5.6);
      
       System.out.printf("Object using default constructor: \n");
       System.out.printf("%s", pw_default);
      
       System.out.print("\n\nObject using parameterised constructor: \n");
       System.out.printf("%s", pw_paramter);
   }

}

Add a comment
Answer #2

The code provided defines three classes: Employee, ProductionWorker, and TestProductionWorker. Here's a breakdown of the code:

  1. The Employee class represents an employee and contains member variables for the employee's name, employee number, and hire date. It has getters and setters for each variable and provides both a default constructor and a parameterized constructor.

  2. The ProductionWorker class extends the Employee class, representing a production worker. It introduces additional member variables for the worker's shift (as an integer) and hourly pay (as a double). It also provides getters and setters for these variables, as well as default and parameterized constructors.

  3. The TestProductionWorker class is a test class that creates instances of ProductionWorker objects using both the default and parameterized constructors. It then prints the information of the objects using the toString() method overridden in the ProductionWorker class.

To run the code and see the output, you can compile and execute the TestProductionWorker class. It will create two ProductionWorker objects, one using the default constructor and the other using the parameterized constructor, and display their information.

Please note that the code formatting might be disrupted in the text-based interface, so make sure to properly format the code in your IDE or text editor before compiling and executing it.


answered by: Mayre Yıldırım
Add a comment
Know the answer?
Add Answer to:
JAVA HELP Design a class named Employee. The class should keep the following information in fields:...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Design a class named Employee. The class should keep the following information in

    WRITE IN C++ ONLY PLEASE. IM USING VISUAL STUDIO CODE.1. Employee and ProductionWorker ClassesDesign a class named Employee. The class should keep the following information in• Employee name• Employee number• Hire dateWrite one or more constructors and the appropriate accessor and mutator functions for the class.Next, write a class named ProductionWorker that is derived from the Employee class. The ProductionWorker class should have member variables to hold the following information:• Shift (an integer)• Hourly pay rate (a double )The workday...

  • (PLEASE UPLOAD ALL PARTS TO THE QUESTION) (IE: PSEUDO CODE AND JAVA CODE TOGETHER NOT ONE...

    (PLEASE UPLOAD ALL PARTS TO THE QUESTION) (IE: PSEUDO CODE AND JAVA CODE TOGETHER NOT ONE OR THE OTHER) Design an Employee class that fields for the following pieces of information: 1) Employee name 2) Employee number Next design a class named ProductionWorker that extends the Employee class. The ProductionWorker class should have fields to hold the following information: 1) Shift number (an integer, such as 1, 2, or 3) 2)Hourly pay The workday is divided into two shifts day...

  • C++ Lab 9B Inheritance Class Production Worker Create a project C2010Lab9b; add a source file Lab...

    C++ Lab 9B Inheritance Class Production Worker Create a project C2010Lab9b; add a source file Lab9b.cpp to the project. Copy and paste the code is listed below: Next, write a class named ProductionWorker that is derived from the Employee class. The ProductionWorker class should have member variables to hold the following information: Shift (an integer) Hourly pay rate (a double) // Specification file for the ProductionWorker Class #ifndef PRODUCTION_WORKER_H #define PRODUCTION_WORKER_H #include "Employee.h" #include <string> using namespace std; class ProductionWorker...

  • (PLEASE UPLOAD ALL PARTS TO THE QUESTION) (IE: PSEUDO CODE AND JAVA CODE TOGETHER NOT ONE...

    (PLEASE UPLOAD ALL PARTS TO THE QUESTION) (IE: PSEUDO CODE AND JAVA CODE TOGETHER NOT ONE OR THE OTHER) Design an Employee class that fields for the following pieces of information: 1) Employee name 2) Employee number Next design a class named ProductionWorker that extends the Employee class. The ProductionWorker class should have fields to hold the following information: 1) Shift number (an integer, such as 1, 2, or 3) 2)Hourly pay The workday is divided into two shifts day...

  • Employee and ProductionWorker Classes DONE IN C# PLEASE Create an Employee class that has properties for...

    Employee and ProductionWorker Classes DONE IN C# PLEASE Create an Employee class that has properties for the following data: • Employee name • Employee number Next, create a class named ProductionWorker that is derived from the Employee class. The ProductionWorker class should have properties to hold the following data: • Shift number (an integer, such as 1, 2, or 3) • Hourly pay rate The workday is divided into two shifts: day and night. The Shift property will hold an...

  • Create the Python code for a program adhering to the following specifications. Write an Employee class...

    Create the Python code for a program adhering to the following specifications. Write an Employee class that keeps data attributes for the following pieces of information: - Employee Name (a string) - Employee Number (a string) Make sure to create all the accessor, mutator, and __str__ methods for the object. Next, write a class named ProductionWorker that is a subclass of the Employee class. The ProductionWorker class should keep data attributes for the following information: - Shift number (an integer,...

  • Using JAVA* Design a class named Person with fields for holding a person’s name, address, and...

    Using 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...

  • Design a class named Person with fields for holding a person's name, address, and telephone number...

    Design a class named Person with fields for holding a person's name, address, and telephone number (all as Strings). Write a constructor that initializes all of these values, and mutator and accessor methods for every field. Next, design a class named Customer, which inherits from the Person class. The Customer class should have a String field for the customer number and a boolean field indicating whether the customer wishes to be on a mailing list. Write a constructor that initializes...

  • this is java m. please use netbeans if you can. 7. Person and Customer Classes Design...

    this is java m. please use netbeans if you can. 7. Person and Customer Classes 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 cus- tomer wishes to...

  • Write a class named PhoneBookEntry that has fields for a person's name and phone number.The class...

    Write a class named PhoneBookEntry that has fields for a person's name and phone number.The class should have a constructor and appropriate accessor and mutator methods. Thenwrite a program that creates at least five PhoneBookEntry objects and stores them in anArrayLitt. Use a loop to display the contents of each object in the ArrayList.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT