我有這個問題,這是我給出的圖,我設法得到了一個解決方案,但實際問題本身是要求我實現get和set方法,我不確定它們是否是這裏適用,mutators是否適用於這裏?
這僅僅是長了一點問題的一部分,並不想使它看起來像我希望我的家庭作業由用戶完成在這裏通過粘貼整個問題,但只是一個疑問,如果get和set方法確實可以實現,我該怎麼做呢?
所以這是我的代碼,我來了這麼遠
public abstract class Property
{
private static int autonumber = 0, propID,area,price;
private String address;
public Property(String addr, int area,int price)
{
autonumber++;
propID = autonumber;
this.area = area;
this.price = price;
}
public abstract double calculateMiscFee();
public int getArea()
{
return area;
}
public void setArea()
{
}
// public double calculateMiscFee()
// {
// return 100*
// }
}
這是我
public abstract class Property
{
private static int autonumber = 0;
private int propID;
private int area;
private double price;
private String address;
private int district;
public Property(String addr, int area,double price, int district)
{
autonumber++;
propID = autonumber;
this.area = area;
this.price = price;
this.district = district;
this.address = addr;
}
public abstract double calculateMiscFee();
public int getArea()
{
return area;
}
public void setArea(int a)
{
area = a;
}
public String getAddress()
{
return address;
}
public void setAddress(String add)
{
address = add;
}
public double getPrice()
{
return price;
}
public void setPrice(double p)
{
price = p;
}
public int getDistrict()
{
return district;
}
public void setDistrict(int disc)
{
district = disc;
}
// public double calculateMiscFee()
// {
// return 100*
// }
public String toString()
{
}
}
掃描得出的問題無法閱讀。你能編輯你的問題來清楚你所問的嗎?你只是想知道如何爲一個類實現getter和setter? –
對不起,鄧肯我的辦公室代理不允許我查看圖像,所以我不知道這是不好的 – noobprogrammer
你的構造函數已經設置了屬性的面積和價格。你的二傳手會做同樣的事情,但一次只能做一個。 'getArea'看起來很適合我...... –