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, 22.06.2019 21:30
How do you take a green screen out of the video while editing?
Answers: 2
question
Computers and Technology, 22.06.2019 22:30
Who needs to approve a change before it is initiated? (select two.) -change board -client or end user -ceo -personnel manager -project manager
Answers: 1
question
Computers and Technology, 23.06.2019 00:00
Suppose you have 9 coins and one of them is heavier than others. other 8 coins weight equally. you are also given a balance. develop and algorithm to determine the heavy coin using only two measurements with the of the balance. clearly write your algorithm in the form of a pseudocode using the similar notation that we have used in the class to represent sorting algorithms
Answers: 1
question
Computers and Technology, 23.06.2019 00:30
Pl i need the answer now ! which one of the following is considered a peripheral? a software b mouse c usb connector d motherboard
Answers: 1
You know the right answer?
JAVA PROGRAMMING Lab - Chapter 10b , Abstract Classes (Interfaces)

Interfaces are also k...
Questions
question
Mathematics, 14.07.2020 02:01
question
Mathematics, 14.07.2020 02:01
question
Mathematics, 14.07.2020 02:01
question
Mathematics, 14.07.2020 02:01
question
Mathematics, 14.07.2020 02:01
Questions on the website: 13722362