mia_tech
02-23-2009, 01:38 AM
I've been asked to create a worker tester for this Classes http://www.codingforums.com/showthread.php?t=159333 that implements polymorphism, although it was discussed on that thread, the worker tester was provided for me, now I need to implement one that uses polymorphism, which I have, I'm posting it here, b/c I'm not completely sure, although I'm calling the same method computePay(double hours), but the method changes depending on the object who calls it (polymorphism)
public class WorkerTester {
public static void main(String[] args)
{
//worker tester
SalariedWorker j = new SalariedWorker("John", 30);
SalariedWorker s = new SalariedWorker("Sam", 20);
HourlyWorker e = new HourlyWorker("Emily", 30);
HourlyWorker t = new HourlyWorker("Tom", 40);
System.out.println(j.getName()+": "+j.computePay(45));
System.out.println(s.getName()+": "+j.computePay(35.50));
System.out.println(e.getName()+": "+e.computePay(55.75));
System.out.println(t.getName()+": "+t.computePay(34.25));
}
}
public class WorkerTester {
public static void main(String[] args)
{
//worker tester
SalariedWorker j = new SalariedWorker("John", 30);
SalariedWorker s = new SalariedWorker("Sam", 20);
HourlyWorker e = new HourlyWorker("Emily", 30);
HourlyWorker t = new HourlyWorker("Tom", 40);
System.out.println(j.getName()+": "+j.computePay(45));
System.out.println(s.getName()+": "+j.computePay(35.50));
System.out.println(e.getName()+": "+e.computePay(55.75));
System.out.println(t.getName()+": "+t.computePay(34.25));
}
}