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

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(); } } }
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...
​​​​​​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...
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...
Please use Java language! With as many as comment! ThanksWrite a static method called "evaluate"...
In Java language Write a static method called "evaluate" that takes a string as a parameter. The string will contain a postfix expression, consisting only of integer operands and the arithmetic operators +, -, *, and / (representing addition, subtraction, multiplication, and division respectively). All operations should be performed as integer operations. You may assume that the input string contains a properly-formed postfix expression. The method should return the integer that the expression evaluates to. The method MUST use a stack...
Write this code in java and don't forget to comment every step. Write a method which...
Write this code in java and don't forget to comment every step. Write a method which asks a baker how hot their water is, and prints out whether it is OK to make bread with the water. If the water is at or above 110F, your method should print "Too Warm." If the water is below 90.5F, print "Too Cold." If it is in between, print "Just right to bake!" For example, if the user inputs the number 100.5, the...
THE LANGUAGE IS JAVA Download the class ArrayManager.java and fill out the method shells with the...
THE LANGUAGE IS JAVA Download the class ArrayManager.java and fill out the method shells with the specifications below. After creating the methods 2) through 5), test them by running the application. The main method allows users to enter a command and, when necessary, additional command specifications. 1) a method displayArray: accepts as a parameter an int array named data prints the array elements to the console, separated by commas and spaces, with the entire array enclosed in braces, e.g., the...
Modify the partition.java program (Listing 7.2) so that the partitionIt() method always uses the highest-index (right)...
Modify the partition.java program (Listing 7.2) so that the partitionIt() method always uses the highest-index (right) element as the pivot, rather than an arbitrary number. (This is similar to what happens in the quickSort1.java program in Listing 7.3.) Make sure your routine will work for arrays of three or fewer elements. To do so, you may need a few extra statements. // partition.java // demonstrates partitioning an array // to run this program: C>java PartitionApp //////////////////////////////////////////////////////////////// class ArrayPar { private...
Provide immediate feedback for each mistyped sentence. To do so, modify the Test class’s present_test method...
Provide immediate feedback for each mistyped sentence. To do so, modify the Test class’s present_test method so that it informs the player a mistake has been made, then display the challenge sentence followed by the player’s sentence so the player can determine where the error lies. #-------------------------------------------------------------------------- # # Script Name: TypingChallenge.rb # Version: 1.0 # Author: Jerry Lee Ford, Jr. # Date: March 2010 # # Description: This Ruby script demonstrates how to apply conditional logic # in order...
how to write in java; Write a method int[] coPrime[int num, int[]numbers] { // instructions are...
how to write in java; Write a method int[] coPrime[int num, int[]numbers] { // instructions are that it returns an array of all the elements of the int[] array numbers which are coprime with x } Note that the array that is returned may be an empty array--you will have to count how many times gcf(x, numbers[i]) == 1. ASSUME numbers is not null and not empty.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT