Question

In: Computer Science

Java instructions: 1. Modify abstract superclass (Employee10A) so it comment out the abstract payPrint method and...

Java instructions:

1. Modify abstract superclass (Employee10A) so it comment out the abstract payPrint method and uses a toString method to print out it’s instance variables. Make sure toString method cannot be overridden.​​​​​​ Source code below:

public abstract class Employee10A {
  
private String firstName, lastName;
static int counter = 0;
  
public Employee10A(String firstName, String lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
  
@Override
public String toString() {
return ("The employee's full name is " + firstName + " " + lastName + ".");
}

abstract void payPrint();
}

2. Create an interface named PartTimeEmployee10A that contains the weekly pay for the Hourly, Salaried, and Commission part time employees as constants: hourly earns $300, salary earns $200, and commission earns $175. Meaning there's no need to calculate weekly pay for hourly, salaried, and commission part time employees, instead use these flat amounts as weekly pay.​

3. Modify all three subclasses (HourlyEmployee10A, SalariedEmployee10A, CommissionEmployee10A) so they implement the interface created. Add code that correctly calculates and sets the weekly pay according to whether the employee is part time or full time. Change the payPrint method in each subclass so that it uses the toString method when printing out the objects. Source code below:

HourlyEmployee10A source code:

public class HourlyEmployee10A extends Employee10A {
  
Scanner sc = new Scanner(System.in);
  
private int hrsWorked, otHrs;
private double hrlyRate, regularPay, otPay, wklyPaycheck;
  
public HourlyEmployee10A(String firstName, String lastName, int hrsWorked,
int otHrs, double hrlyRate, double regularPay, double otPay) {
  
super (firstName, lastName);
this.hrsWorked = hrsWorked;
this.otHrs = otHrs;
  
if (hrsWorked > 40) {
System.out.println("Enter the number of overtime hours worked "
+ "by the employee:");
otHrs = sc.nextInt();

otPay = ((hrlyRate * 1.5) * otHrs);
regularPay = hrlyRate * 40;
}
else {
otPay = 0;
regularPay = hrlyRate * hrsWorked;
}
  
this.hrlyRate = hrlyRate;
this.regularPay = regularPay;
this.otPay = otPay;
counter++;
}
  
//method that calculates the weekly paycheck
public void WklyPaycheck() {
wklyPaycheck = regularPay + otPay;
}
  
//getter(method) that retrieves the "wklyPaycheck"
public double getWklyPaycheck() {
return wklyPaycheck;
}
  
@Override
public String toString() {
return String.format("%s The employee is an Hourly Employee and its "
+ "weekly paycheck amount is $%.2f.", super.toString(), wklyPaycheck);
}


@Override
public void payPrint() {
WklyPaycheck();
}
}

SalariedEmployee10A source code:

public class SalariedEmployee10A extends Employee10A {
  
private double yrlySalary, bonusPercent, wklyPaycheck;
private static final double weeks = 52;
private static final double toDecimal = 100;
  
public SalariedEmployee10A(String firstName, String lastName, double yrlySalary,
double bonusPercent) {
  
super(firstName, lastName);
this.yrlySalary = yrlySalary;
this.bonusPercent = bonusPercent;
counter++;
}
  
public void WklyPaycheck() {
wklyPaycheck = (yrlySalary * (1.0 + bonusPercent/toDecimal)) / weeks;
}
  
@Override
public String toString() {
return String.format("%s The employee is a Salaried Employee and its "
+ "weekly paycheck amount is $%.2f.", super.toString(), wklyPaycheck);
}


@Override
public void payPrint() {
WklyPaycheck();
}
}

CommissionEmployee10A source code:

public class CommissionEmployee10A extends Employee10A {

private int soldItems;
private double itemCost, wklyPaycheck;
private static final double baseComm = 200;
private static final double employeePercent = .1;
  
public CommissionEmployee10A(String firstName, String lastName, int soldItems,
double itemCost) {
  
super(firstName, lastName);
this.soldItems = soldItems;
this.itemCost = itemCost;
counter++;
}
  
public void WklyPaycheck() {
wklyPaycheck = baseComm + ((employeePercent) * (double)soldItems * itemCost);
}
  
@Override
public String toString() {
return String.format("%s The employee is a Commission Employee and its "
+ "weekly paycheck amount is $%.2f.", super.toString(), wklyPaycheck);
}


@Override
public void payPrint() {
WklyPaycheck();
}
}

4. Modify driver class (EmployeeTest10A) so it adds code to create a part time employee of each type and a fulltime employee of each type (6 employees/objects). Print all 6 objects using payPrint. Add all 6 objects to the superclass array. Use the instanceof and downcasting to search for and print out the object of your choice. Source code below:

public class EmployeeTest10A {
  
public static void main(String[] args) {
  
Scanner sc = new Scanner(System.in);
  
String firstName, lastName;
int otHrs = 0;
int answer, hrsWorked, soldItems;
double otPay = 0;
double regularPay = 0;
double hrlyRate, wklyPaycheck, bonus, itemCost;
  
//create an array of type Employee10A to store objects of its subclasses
Employee10A[] employees = new Employee10A[3];
  
System.out.println("Enter any number to continue or enter a -1 to exit "
+ "the program.");
answer = sc.nextInt();
  
while(answer != -1) {
  
System.out.println("Please provide information for Hourly Employee.");
System.out.println("Enter the employee's first name:");
firstName = sc.next();
  
System.out.println("Enter the employee's last name:");
lastName = sc.next();
  
System.out.println("Enter the employee's hourly rate of pay:");
hrlyRate = sc.nextDouble();

System.out.println("Enter the number of hours worked by the employee:");
hrsWorked = sc.nextInt();
  
//creating object of "HourlyEmployee10A" and storing it in Employee10A type array
employees[0] = new HourlyEmployee10A(firstName, lastName, hrsWorked, otHrs, hrlyRate, regularPay, otPay);
// calling method from "HourlyEmployee10A" to calculate weekly paycheck
employees[0].payPrint();
// printing results
System.out.println(employees[0]);
  
System.out.println("\nPlease provide information for Salaried Employee.");
System.out.println("Enter the employee's first name:");
firstName = sc.next();

System.out.println("Enter the employee's last name:");
lastName = sc.next();

System.out.println("Enter the employee's yearly salary:");
regularPay = sc.nextDouble();

System.out.println("Enter the employee's bonus percent:");
bonus = sc.nextDouble();

//creating object of "SalariedEmployee10A" and storing it in Employee10A type array
employees[1] = new SalariedEmployee10A(firstName, lastName, regularPay, bonus);
//calling method from "SalariedEmployee10A" to calculate weekly paycheck
employees[1].payPrint();
// printing results
System.out.println(employees[1]);
  
System.out.println("\nPlease provide information for Commission Employee.");
System.out.println("Enter the employee's first name:");
firstName = sc.next();

System.out.println("Enter the employee's last name:");
lastName = sc.next();

System.out.println("Enter the number of items sold by the employee:");
soldItems = sc.nextInt();

System.out.println("Enter the price of each item:");
itemCost = sc.nextDouble();

//creating object of "CommissionEmployee10A" and storing it in Employee10A type array
employees[2] = new CommissionEmployee10A(firstName, lastName, soldItems, itemCost);
//calling method from "CommissionEmployee10A" to calculate weekly paycheck
employees[2].payPrint();
//printing results
System.out.println(employees[2]);
  
System.out.println("\nEnter any number to continue or enter a -1 to "
+ "exit the program and calculate the total number of paychecks.");
answer = sc.nextInt();
}

System.out.println("\nTotal number of paychecks calculated: " + Employee10A.counter);
}
}

Solutions

Expert Solution

Interface:

Code:

package assignment;

import java.util.Scanner;

class Employee10A {
      
       private String firstName, lastName;
       static int counter = 0;
      
       public Employee10A(String firstName, String lastName) {
       this.firstName = firstName;
       this.lastName = lastName;
       }
      
       public String toString() {
       return ("The employee's full name is " + firstName + " " + lastName + ".");
       }

       public void payPrint() {
           // TODO Auto-generated method stub
          
       }

       //abstract void payPrint();
}

      
       class HourlyEmployee10A extends Employee10A implements PartTimeEmployee10A{
      
       Scanner sc = new Scanner(System.in);
      
       private int hrsWorked, otHrs;
       private double regularPay, otPay, wklyPaycheck;
      
       public HourlyEmployee10A(String firstName, String lastName, int hrsWorked,
       int otHrs, double regularPay, double otPay) {
      
       super (firstName, lastName);
       this.hrsWorked = hrsWorked;
       this.otHrs = otHrs;
      
       if (hrsWorked > 40) {
       System.out.println("Enter the number of overtime hours worked "
       + "by the employee:");
       otHrs = sc.nextInt();

       otPay = ((hrsearns * 1.5) * otHrs);
       regularPay = hrsearns * 40;
       }
       else {
       otPay = 0;
       regularPay = hrsearns * hrsWorked;
       }
      
       //this.hrsearns = hrsearns;
       this.regularPay = regularPay;
       this.otPay = otPay;
       counter++;
       }      
       //method that calculates the weekly paycheck
       public void WklyPaycheck() {
       wklyPaycheck = regularPay + otPay;
       }
      
       //getter(method) that retrieves the "wklyPaycheck"
       public double getWklyPaycheck() {
       return wklyPaycheck;
       }
      
       public String toString() {
       return String.format("%s The employee is an Hourly Employee and its "
       + "weekly paycheck amount is $%.2f.", super.toString(), wklyPaycheck);
       }


       public void payPrint() {
       WklyPaycheck();
       }
       }
       //SalariedEmployee10A source code:

       class SalariedEmployee10A extends Employee10A implements PartTimeEmployee10A {
      
       private double yrlySalary, bonusPercent, wklyPaycheck;
       private static final double weeks = 52;
       private static final double toDecimal = 100;
      
       public SalariedEmployee10A(String firstName, String lastName,double bonusPercent) {
      
       super(firstName, lastName);
       //this.salaryearns = salaryearns;
       this.bonusPercent = bonusPercent;
       counter++;
       }
      
       public void WklyPaycheck() {
       wklyPaycheck = (salaryearns * (1.0 + bonusPercent/toDecimal)) / weeks;
       }
      
       public String toString() {
       return String.format("%s The employee is a Salaried Employee and its "
       + "weekly paycheck amount is $%.2f.", super.toString(), wklyPaycheck);
       }

       public void payPrint() {
       WklyPaycheck();
       }
       }

       //CommissionEmployee10A source code:

       class CommissionEmployee10A extends Employee10A implements PartTimeEmployee10A {

       private int soldItems;
       private double itemCost, wklyPaycheck;
       //private static final double baseComm = 200;
       private static final double employeePercent = .1;
      
       public CommissionEmployee10A(String firstName, String lastName, int soldItems,
       double itemCost) {
      
       super(firstName, lastName);
       this.soldItems = soldItems;
       this.itemCost = itemCost;
       counter++;
       }
      
       public void WklyPaycheck() {
       wklyPaycheck = commision + ((employeePercent) * (double)soldItems * itemCost);
       }
       public String toString() {
       return String.format("%s The employee is a Commission Employee and its "
       + "weekly paycheck amount is $%.2f.", super.toString(), wklyPaycheck);
       }
       public void payPrint() {
       WklyPaycheck();
       }
       }
       public class EmployeeTest10A implements PartTimeEmployee10A {
      
       public static void main(String[] args) {
      
       Scanner sc = new Scanner(System.in);
      
       String firstName, lastName;
       int otHrs = 0;
       int answer, hrsWorked, soldItems;
       double otPay = 0;
       double regularPay = 0;
       double hrlyRate, wklyPaycheck, bonus, itemCost;
      
       //create an array of type Employee10A to store objects of its subclasses
       //Employee10A[] employees = new Employee10A[3];
       HourlyEmployee10A hour;
       SalariedEmployee10A salary;
       CommissionEmployee10A comm;
      
       System.out.println("Enter any number to continue or enter a -1 to exit "
       + "the program.");
       answer = sc.nextInt();
      
       while(answer != -1) {
      
       System.out.println("Please provide information for Hourly Employee.");
       System.out.println("Enter the employee's first name:");
       firstName = sc.next();
      
       System.out.println("Enter the employee's last name:");
       lastName = sc.next();
      

       System.out.println("Enter the number of hours worked by the employee:");
       hrsWorked = sc.nextInt();
      
       //creating object of "HourlyEmployee10A" and storing it in Employee10A type array
       System.out.println("weekly pay for the hourly: "+PartTimeEmployee10A.hrsearns);
       hour = new HourlyEmployee10A(firstName, lastName, hrsWorked, otHrs, PartTimeEmployee10A.hrsearns, regularPay);
       // calling method from "HourlyEmployee10A" to calculate weekly paycheck
       hour.payPrint();
       // printing results
       System.out.println(hour);
       System.out.println(hour instanceof Employee10A );//instaceof
      
       System.out.println("\nPlease provide information for Salaried Employee.");
       System.out.println("Enter the employee's first name:");
       firstName = sc.next();

       System.out.println("Enter the employee's last name:");
       lastName = sc.next();

       System.out.println("Enter the employee's bonus percent:");
       bonus = sc.nextDouble();
       System.out.println("Salary earns: "+PartTimeEmployee10A.salaryearns);
       //creating object of "SalariedEmployee10A" and storing it in Employee10A type array
       salary = new SalariedEmployee10A(firstName, lastName, PartTimeEmployee10A.salaryearns);
       //calling method from "SalariedEmployee10A" to calculate weekly paycheck
salary.payPrint();
       // printing results
System.out.println(salary);
       System.out.println(salary instanceof SalariedEmployee10A);//instaceof
      
       System.out.println("\nPlease provide information for Commission Employee.");
       System.out.println("Enter the employee's first name:");
       firstName = sc.next();
       System.out.println("Enter the employee's last name:");
       lastName = sc.next();
       System.out.println("Enter the number of items sold by the employee:");
       soldItems = sc.nextInt();

       System.out.println("Enter the price of each item:");
       itemCost = sc.nextDouble();
       System.out.println("commision for parttime employess"+PartTimeEmployee10A.commision);

       //creating object of "CommissionEmployee10A" and storing it in Employee10A type array
       comm = new CommissionEmployee10A(firstName, lastName, soldItems, itemCost);
       //calling method from "CommissionEmployee10A" to calculate weekly paycheck
       comm.payPrint();
       //printing results
       System.out.println(comm);
       System.out.println(comm instanceof CommissionEmployee10A );//instanceof
      
       System.out.println("\nEnter any number to continue or enter a -1 to "
       + "exit the program and calculate the total number of paychecks.");
       answer = sc.nextInt();
       }
       System.out.println("\nTotal number of paychecks calculated: " + Employee10A.counter);
       }}

Inteface:

package assignment;

public interface PartTimeEmployee10A {
   public final int hrsearns= 300;
public final int salaryearns = 200;
public final int commision = 175;

}

Note:***I hope i met your requirements*****If its right please give me upvote*****Thank you.....


Related Solutions

Create 3 Classes per the following instructions: 1) Create an abstract parent superclass called MobileDevices and...
Create 3 Classes per the following instructions: 1) Create an abstract parent superclass called MobileDevices and include only the attributes that are common to both cellphones and tablets like iPads. Also create at least one abstract method. 2) Create a child class that extends the MobileDevices class called DeviceType that has attributes and methods regarding the type of device. 3) Create a third class that extends the DeviceType class called DeviceBrand that has attributes and methods for both Apple and...
Modify the processFile method so that it will compile and it will not produce a runtime...
Modify the processFile method so that it will compile and it will not produce a runtime error: public static void processFile(File file) { File input = "contents.txt"; String line = null; try { input = new File(file); while ((line = input.readLine()) != null) { System.out.println(line); } return; } finally { if (file != null) { file.close(); } } }
Write in Java Modify the parent class (Plant) by adding the following abstract methods:(The class give...
Write in Java Modify the parent class (Plant) by adding the following abstract methods:(The class give in the end of question) a method to return the botanical (Latin) name of the plant a method that describes how the plant is used by humans (as food, to build houses, etc) Add a Vegetable class with a flavor variable (sweet, salty, tart, etc) and 2 methods that return the following information: list 2 dishes (meals) that the vegetable can be used in...
Modify the method so that the item with the highest key is not only returned by...
Modify the method so that the item with the highest key is not only returned by the method but is also removed from the array. Call the method removeMax(). // highArray.java // demonstrates array class with high-level interface // to run this program: C>java HighArrayApp //////////////////////////////////////////////////////////////// class HighArray { private long[] a; // ref to array a private int nElems; // number of data items //----------------------------------------------------------- public HighArray(int max) // constructor { a = new long[max]; // create the array...
Modify the insertionSort() method in insertSort.java so it counts the number of copies and the number...
Modify the insertionSort() method in insertSort.java so it counts the number of copies and the number of comparisons it makes during a sort and displays the totals. To count comparisons, you will need to break up the double condition in the inner while loop. Use this program to measure the number of copies and comparisons for different amounts of inversely sorted data. Do the results verify O(N2 ) efficiency? Do the same for almost-sorted data (only a few items out...
​​​​​​This is an assignment that I'm having trouble figuring out in python: Modify Node class so...
​​​​​​This is an assignment that I'm having trouble figuring out in python: Modify Node class so it has a field called frequency and initialize it as one. Add a search function. If a number is in the list, return its frequency. Modify Insert function. Remove push, append, and insertAfter as one function called insert(self, data). If you insert a data that is already in the list, simply increase this node’s frequency. If the number is not in the list, add...
Finish the following java question:  Modify a Encryption program so that it uses the following encryption algorithm:...
Finish the following java question:  Modify a Encryption program so that it uses the following encryption algorithm: Every letter (both uppercase and lowercase) converted to its successor except z and Z, which are converted to 'a' and 'A' respectively (i.e., a to b, b to c, …, y to z, z to a, A to B, B to C, …, Y to Z, Z to A) Every digit converted to its predecessor except 0, which is converted to 9 (i.e., 9...
In Java, Modify “Producer and Consumer Problem” from lecture note so that it can use all...
In Java, Modify “Producer and Consumer Problem” from lecture note so that it can use all buffer space, not “buffer_size – 1” as in the lecture note. This program should work as follows: 1. The user will run the program and will enter two numbers on the command line. Those numbers will be used for buffer size and counter limit. 2. The main program will then create two separate threads, producer and consumer thread. 3. Producer thread generates a random...
JAVA programming language Modify the following code. Make changes so that Movies can be sorted by...
JAVA programming language Modify the following code. Make changes so that Movies can be sorted by title ----------------------------------------------------------------- package Model; import java.time.Duration; import java.time.LocalDate; import java.util.ArrayList; import java.util.List; // TODO - Modify the movie class so that Java knows how to compare two Movies for sorting by title public class Movie extends DataStoreObj { private String title; private String description; private LocalDate releaseDate; private Duration runningTime; private Rating rating; private List<Genre> genres = new ArrayList<>(); private List<Actor> actors = new...
Modify Account Class(Java programming) used in the exercises such that ‘add’ and ‘deduct’ method could only...
Modify Account Class(Java programming) used in the exercises such that ‘add’ and ‘deduct’ method could only run if the account status is active. You can do this adding a Boolean data member ‘active’ which describes account status (active or inactive). A private method isActive should also be added to check ‘active’ data member. This data member is set to be true in the constructor, i.e. the account is active the first time class Account is created. Add another private method...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT