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

/*Java program to create a super class Employee and a sub class ProductionWorker .Then constructors
of super class and class are added.Accessor and mutator methods for all the fields are added.

In main program create the object of subclass and pass the employee name,number,hiredate, shift,hourly pay rate,
and hours are passed to the constructor. and the program computes the pay of an employee and display all the informations*/

//The super class Employee
class Employee
   {
   //data fields
   private String name;
   private String hiredate;
   private String number;
   //constructors to set name,number and hiredate
   public Employee(String n,String hd,String num)
       {
           name=n;
           hiredate=hd;
           number=num;
       }
   //accessors methods of Employee class defined below
   public String getName()
       {
       return name;
       }
   public String getHireDate()
       {
       return hiredate;
       }
   public String getNumber()
       {
       return number;
       }


   //mutator methods of Employee class defined below
   public void setName(String n)
       {
       name=n;
       }
   public void setHireDate(String hd)
       {
       hiredate=hd;
       }
   public void setNumber(String n)
       {
       number=n;
       }

   }

class ProductionWorker extends Employee
   {
       private int shift;
       private double hourlyRate;
       private int hours;

       //constructors to set name,number and hiredate, shift,hourly rate and hours
       public ProductionWorker(String ename,String enumber,String hd,int sh,double hrate,int hr)
           {
               super(ename,hd,enumber);
               shift=sh;
               hourlyRate=hrate;
               hours=hr;
           }


       //accessors methods of ProductionWorker class defined below
       public int getHours()
           {
           return hours;
           }

       public int getShift()
           {
           return shift;
           }
       public double getHourlyRate()
           {
           return hourlyRate;
           }

       //mutator methods of ProductionWorker class defined below
       public void setShift(int sh)
           {
           shift=sh;
           }
       public void setHourlyRate(double hr)
           {
           hourlyRate=hr;
           }

       public void setHours(int hr)
           {
           hours=hr;
           }

       public String getName()
           {
           return super.getName();
           }
       public String getHireDate()
           {
           return super.getHireDate();
           }
       public String getNumber()
               {
               return super.getNumber();
           }

       //calculate the pay
       public double calculatePay()
                   {
                   double pay=hours*hourlyRate;
                   return pay;
           }
       }


public class TestEmp
   {
   public static void main(String args[])
       {
       //test1
       ProductionWorker worker1=new ProductionWorker("Harry Biston","222B","12-4-2015",1,100.00,6);
       System.out.println("Employee Name   :"+worker1.getName());
       System.out.println("Employee Number   :"+worker1.getNumber());
       System.out.println("Hire Date   :"+worker1.getHireDate());
       String shift=worker1.getShift()==1? " Day":" Night";
       System.out.println("Shift       :"+shift);
       System.out.println("Hourly rate   :"+worker1.getHourlyRate());
       System.out.println("Hours worked   :"+worker1.getHours());
       System.out.println("Pay   =   :"+worker1.calculatePay());
   System.out.println("\n");
       //test2
       ProductionWorker worker2=new ProductionWorker("SSg Mishra","124H","22-1-2010",2,120.00,5);
       System.out.println("Employee Name   :"+worker2.getName());
       System.out.println("Employee Number   :"+worker2.getNumber());
       System.out.println("Hire Date   :"+worker2.getHireDate());
       shift=worker2.getShift()==1? " Day":" Night";
       System.out.println("Shift       :"+shift);
       System.out.println("Hourly rate   :"+worker2.getHourlyRate());
       System.out.println("Hours worked   :"+worker2.getHours());
       System.out.println("Pay   =   :"+worker2.calculatePay());
       }

}

--------------------------------------------------------

output


Related Solutions

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...
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...
[20 marks] (TestRobot.java) Design a class named Robot. The Robot class has three private data fields:...
[20 marks] (TestRobot.java) Design a class named Robot. The Robot class has three private data fields: position x, position y, and the direction (east, south, west, and north). Assume that positive x points to the east and positive y points to the south, and initially x = 0, y = 0, direction = "east". Create a no-arg constructor and another constructor which sets the three data fields. Create the accessors and mutators for the three data fields. Create a method...
[20 marks] (TestRobot.java) Design a class named Robot. The Robot class has three private data fields:...
[20 marks] (TestRobot.java) Design a class named Robot. The Robot class has three private data fields: position x, position y, and the direction (east, south, west, and north). Assume that positive x points to the east and positive y points to the south, and initially x = 0, y = 0, direction = "east". Create a no-arg constructor and another constructor which sets the three data fields. Create the accessors and mutators for the three data fields. Create a method...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT