THINK FIRST·CODE LATER

← All labs

Payable interface and polymorphism

Problem

Write an interface Payable with one method double pay().

Write two classes implementing it:

  • HourlyWorker(String name, double hours, double rate)pay() returns hours * rate, and hours above 40 are paid 1.5 times;
  • SalariedWorker(String name, double monthly)pay() returns monthly.

PayrollApp reads: the hourly worker's name, hours and rate, then the salaried worker's name and monthly salary. It puts both in a Payable[] array, prints each pay with two decimals as name: 1000.00, then the total as Total: 3000.00.

Write it here or in your IDE, then paste it. Compile and test it yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.