作业帮 > 综合 > 作业

JAVA 关于class 的编程!

来源:学生作业帮 编辑:拍题作业网作业帮 分类:综合作业 时间:2024/04/27 21:02:08
JAVA 关于class 的编程!
In the following problems,you will build a series of Java classes,which you should be able to use with the following test program (containing the expected results as printed messages):
public class TestWorkers
{
public static void main(String[] args)
{
Worker[] workers = new Worker[4];
workers[0] = new HourlyWorker("John",6);
workers[1] = new SalariedWorker("Jane",10);
workers[2] = new HourlyWorker("Bob",8);
workers[3] = new SalariedWorker("Boss",15);
int[] hours = { 30,35,60,20 };
for (int i = 0; i < workers.length; i++)
{
System.out.println(workers[i].getName() + "'s wage for "
+ hours[i] + " hours with $" + workers[i].getRate()
+ "/hour = " + workers[i].computePay(hours[i]));
}
System.out.println("Expected output:");
System.out.println("John's wage for 30 hours with $6.0/hour = 180.0");
System.out.println("Jane's wage for 35 hours with $10.0/hour = 400.0");
System.out.println("Bob's wage for 60 hours with $8.0/hour = 560.0");
System.out.println("Boss's wage for 20 hours with $15.0/hour = 600.0");
}
}

Questions:
1.\x05Does this program exhibit any polymorphic characteristics?  If so where?
2.\x05Can you make the ‘Worker’ class abstract?  If not, why not?
3.\x05If this project was also expanded to figure out taxes on wages where would the code for this calculation best be placed?
题目实在太长了.所以用截图了..图片看的到么? 还有一天就要交了.100分求编程.
Worker这个类你没贴出来.而且你也不给点分!
再问: 一个题25分,一共4题~
再答: public class TestWorkers { private static TestWorkers mTestWorkers; private static TestWorkers getInstance() { return new TestWorkers(); } public static void main(String[] args) { if (mTestWorkers == null) { mTestWorkers = getInstance(); } Worker[] workers = new Worker[4]; workers[0] = mTestWorkers.new HourlyWorker("John", 6); workers[1] = mTestWorkers.new SalariedWorker("Jane", 10); workers[2] = mTestWorkers.new HourlyWorker("Bob", 8); workers[3] = mTestWorkers.new SalariedWorker("Boss", 15); int[] hours = { 30, 35, 60, 20 }; for (int i = 0; i < workers.length; i++) { System.out.println(workers[i].getName() + "'s wage for " + hours[i] + " hours with $" + workers[i].getRate() + "/hour = " + workers[i].computePay(hours[i])); } System.out.println("Expected output:"); System.out.println("John's wage for 30 hours with $6.0/hour = 180.0"); System.out.println("Jane's wage for 35 hours with $10.0/hour = 400.0"); System.out.println("Bob's wage for 60 hours with $8.0/hour = 560.0"); System.out.println("Boss's wage for 20 hours with $15.0/hour = 600.0"); } public class Worker { private String name; private int salaryRate; public Worker() { name = null; salaryRate = 0; } public Worker(String n, int s) { name = n; salaryRate = s; } public String getName() { return name; } public int getRate() { return salaryRate; } public double computePay(int hours) { return hours * salaryRate; } } 在的话速度回一下我继续贴
再问: 我在。。我这边是凌晨六点。。。明天白天看~~我用eclipse~
再答: public class HourlyWorker extends Worker{ public HourlyWorker (String n, int s) { super(n, s); } public double computePay(int hours) { if (hours