3. המתודות של למימוש דוגמה נראהset()ו-get():
public class Car {
private int price;
private int customerPrice;
private int customs;
private int tax;
private int registration;
public int getCustoms() {
return customs;
}
public void setCustoms(int customs) {
this.customs = customs;
}
public int getTax() {
return tax;
}
public void setTax(int tax) {
this.tax = tax;
}
public int getRegistration() {
return registration;
}
public void setRegistration(int registration) {
this.registration = registration;
}
private int getRealPrice() {
return price;
}
public void setPrice(int price) {
if (price<0)
System.out.println("Negative value not allowed!");
else if (price>100000)
System.out.println("Can't afford to buy at more than 100,000!");
else {
this.price = price;
setCustomerPrice(price);
}
}
private void setCustomerPrice(int price) {
customerPrice = price+getTax()+getCustoms()+getRegistration();
}
public int getPrice() {
if (getRealPrice()==0)
System.out.println("Price calculated without purchase price");
if (getRegistration()==0)
System.out.println("Price calculated without registration fees");
if (getTax()==0)
System.out.println("Price calculated without tax amount");
if (getCustoms()==0)
System.out.println("Price calculated without customs fees");
return customerPrice;
}
}