subject

JAVA PROGRAMMING Lab - Chapter 10b , Abstract Classes (Interfaces)

Interfaces are also known as "contracts" because an Interface enforces certain behaviors for all subclasses in the hierarchy of the superclass - (i. e. all Classes that inherit from the super class which is an Abstract base Class). However, that behavior for all subclasses can be overridden and specialized for each subclass - POLYMORPHISM. Let's Learn more:

1. Read Chapter 10 sections 10.8 through 10.12

2. Chapter Review Questions and Exercises.

3. [10 points] submit updated FactoryWorker. java

[10 points] submit updated SalesWorker. java

FactoryWorker. java and SalesWorker. java implements our Interface:

Worker. javaPreview the document.

/* Worker Interface */

public interface Worker {

public double calculateOvertimePay(int hours);

public double calculateRegPay(int hours);

public void printPayStub(int hours);

public String toString();

}

We no longer need a specialized calculations for pay: calculateFacPay() and calculateSalPay()

INSTEAD - we will implement the Interface Worker. java and our calculations for Reg pay and Overtime pay will INCLUDE "implement" the requirements for the calculations as described in our last lab for each classification of worker: Factory or Sales. This will illustrate polymorphic behavior - where at run-time our program figures out which calculateRegPay() / calculateOvertimePay() to call and calls the correct one depending on the object instantiated.

Since Worker. java is an Interface, it is the "contract" on how I can use objects the implement Class Worker. I can write the test driver program before you have even written the implementation. Once you have completed your implementation, put all your .java files in the same directory, compile the test driver, and run the test driver. If all goes well you have successfully implemented our Worker Interface!

Test Driver: WorkerInterfaceT. javaPreview the document

import java. util. Scanner;

public class WorkerInterfaceT {

public static void main(String[]args){

Scanner input = new Scanner(System. in);

Worker w[] = new Worker[3];

for (int i = 0; i < w. length; i++)

{

System. out. println("Please enter S for Sales and F for Factory");

String wc = input. nextLine();

if(wc. equalsIgnoreCase("F")) {

w[i] = new FactoryWorker();

//get input and call your Factory setters()

}

else {

w[i] = new SalesWorker();

//get input and call your Sales setters()

}

System. out. println("Enter hours worked");

int hours = input. nextInt();

//polymorphic behavior

w[i].printPayStub(hours);

input. nextLine(); // clear input buffer

}

}

}

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 17:30
Write pseudocode to represent the logic of a program that allows the user to enter a value. the program multiplies the value by 10 and outputs the result.
Answers: 1
question
Computers and Technology, 24.06.2019 00:30
Match the sentence fragment in the first column with the appropriate ending in the second column. a little per favore?
Answers: 1
question
Computers and Technology, 24.06.2019 01:00
Me if you do then you get 10 points and brainliest
Answers: 1
question
Computers and Technology, 24.06.2019 20:50
Which key function of a business involves finding, targeting, attracting, and connecting with the right customers?
Answers: 3
You know the right answer?
JAVA PROGRAMMING Lab - Chapter 10b , Abstract Classes (Interfaces)

Interfaces are also k...
Questions
question
Mathematics, 24.02.2021 03:40
question
Mathematics, 24.02.2021 03:40
question
Mathematics, 24.02.2021 03:40
question
Computers and Technology, 24.02.2021 03:40
question
Mathematics, 24.02.2021 03:40