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, 21.06.2019 18:20
Write the pseudocode for the following: a function called fahrenheittocelsius that accepts a real fahrenheit temperature, performs the conversion, and returns the real celsius temperature. a function called celsiustofahrenheit that accepts a real celsius temperature, performs the conversion, and returns the real fahrenheit temperature. a main module that asks user to enter a fahrenheit temperature, calls the fahrenheittocelsius function, and displays the celsius temperature with a user-friendly message. it then asks the user to enter a celsius temperature, calls the celsiustofahrenheit function, and displays the fahrenheit temperature with a user-friendly message.
Answers: 1
question
Computers and Technology, 23.06.2019 03:30
Many everyday occurrences can be represented as a binary bit. for example, a door is open or closed, the stove is on or off, and the fog is asleep or awake. could relationships be represented as a binary value? give example.
Answers: 1
question
Computers and Technology, 23.06.2019 13:30
Anetwork security application that prevents access between a private and trusted network and other untrusted networks
Answers: 1
question
Computers and Technology, 23.06.2019 20:00
How much current flows through the alternator brushes? a. 2–5 a b. 25–35 a, depending on the vehicle c. 5–10 a d. 10–15 a
Answers: 2
You know the right answer?
JAVA PROGRAMMING Lab - Chapter 10b , Abstract Classes (Interfaces)

Interfaces are also k...
Questions
question
Mathematics, 29.06.2020 15:01
question
Mathematics, 29.06.2020 15:01
question
English, 29.06.2020 15:01
question
English, 29.06.2020 15:01
question
Social Studies, 29.06.2020 15:01
question
Mathematics, 29.06.2020 15:01
Questions on the website: 13722361