java - 唔知邊度錯

2006-11-05 12:59 am
http://us.f13.yahoofs.com/bc/454c5620_92b/bc/TestWorkman.java?bf5qFTFBx8ZnrRi5

--------------

最尾o個度, 要create 3 workman objects with values:::
idnum hours special
801 default default
802 10 default
803 12 true

然後print idnum + pay for the 3 objects and
the class count by calling the appropriate methods.

回答 (1)

2006-11-05 1:19 am
✔ 最佳答案
import javax.swing.*;

class Workman{

private int idNum;
private int hours=8;
private boolean special=false;
private static int count=0;
private static final double RATE1=8.6;
private static final double RATE2=7.3;

public Workman(int num) {
idNum=num;
count++;
}

public Workman(int n1, int n2) {
idNum=n1;
hours=n2;
count++;
}

public Workman(int n1, int n2, boolean special) {
idNum=n1;
hours=n2;
this.special=special;
count++;
}

public static int getCount() {
return count;
}
/*
public void setSpecial(boolean special){
boolean x;
special=x;
}

public int getNum() {
return idNum;
}
*/
public double getPay() {
double pay;
if (special==true)
pay=hours*RATE1;
else
pay=hours*RATE2;
return pay;
}

}//end of classWorkman

public class TestWorkman {
public static void main (String[] arg) {

Workman id801 = new Workman(801);
System.out.println("The pay of idNum: 801 is " + id801.getPay() );

Workman id802 = new Workman(802, 10);
System.out.println("The pay of idNum: 802 is " + id802.getPay() );

Workman id803 = new Workman(803, 12, true);
System.out.println("The pay of idNum: 803 is " + id803.getPay() );

}//end of main

}//end of TestWorkman


收錄日期: 2021-04-12 18:12:25
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20061104000051KK03294

檢視 Wayback Machine 備份