JAVA程式問題 請各位大大幫忙~感謝
class CTrapezoid{
int upper;
int base;
int height;
double area()
{return(upper+base)*height/2;
}
}
public class koreha {
public static void main(String[] args) {
CTrapezoid ctr=new CTrapezoid();
ctr.upper=4;
ctr.base=9;
ctr.height=5; }}
1.試在CTrapezoid類別裡定義成員函數show( ),印出各個資料成員之值
2.在main( )method裡出呼叫show( )及area( ) method
因為只剩這兩個部份想不出來,所以請大家幫忙一下,謝謝
1 個解答
- 1 0 年前最佳解答
class CTrapezoid{
int upper;
int base;
int height; double area() {
return(upper+base)*height/2;
}
void show() {
System.out.println("upper: " + upper);
System.out.println("base: " + base);
System.out.println("height: " + height);
}
}
public class koreha {
public static void main(String[] args) {
CTrapezoid ctr=new CTrapezoid();
ctr.upper=4;
ctr.base=9;
ctr.height=5;
ctr.show();
System.out.println("Area: " + ctr.area());
}
}
只是 print out class 的資訊而已,不知道您卡在哪裡?
參考資料: none