ITI0011-2016:harjutus 10 lihtsam
Redaktsioon seisuga 18. märts 2016, kell 07:00 kasutajalt Ago (arutelu | kaastöö) (Uus lehekülg: ' == Üldine == Kaitsmised: 21. - 22. märts<br /> Kaust gitis: EX10A<br /> See on lihtsam variant harjutus 10st (ITI0011:harjutus 10 == Ülesanne == Realiseerida <code>Ex...')
Üldine
Kaitsmised: 21. - 22. märts
Kaust gitis: EX10A
See on lihtsam variant harjutus 10st (ITI0011:harjutus 10
Ülesanne
Realiseerida ExpensiveCarShop
, mis implementeerib CarShop
liidest. Realiseeritav funktsionaalsus:
- auto müümisel pannakse selle hinnale 10% otsa. Ehk kui auto hind on 100 eurot, siis
sellCar
selle auto kohta tagastab 110. sellCar
tagastab suvalise auto nimetatud mudeliga. Kui mudel onnull
, siis tagastab suvalise auto.
Mall
CarShop.java: <source lang="java"> /**
* Car shop interface. */
public interface CarShop {
/** * Car shop buys a car. Car will be added to the owned cars. * @param car Car to buy. */ void buyCar(Car car);
/** * Car shop sells a car with the specified model. * Car will be removed from the owned cars. * @param model Car with the specified model is sold. * @return The price of the sold car. Negative if no car found. * Negative if no cars with specified model exist (out of stock). */ double sellCar(String model);
/** * Gets the amount of cars with specified model. If no cars * with specified model exist, returns 0. If specified model is null, * returns the amount of all the cars. * @param model Model to count. If null, the amount of all the cars is returned. * @return The amount of cars with specified model. If model is null, * total amount of cars. */ int getAmount(String model);
}
</source>
Car.java <source lang="java"> /**
* Car object which is operated by CarShop. */
public class Car {
/** * Model of the car. */ private String model;
/** * Price of the car. */ private double price;
/** * Constructor. * @param model Model of the car. * @param price Price of the car. */ public Car(String model, double price) { this.model = model; this.price = price; }
/** * Gets the price of the car (in euros). * * @return Car price. */ public double getPrice() { return price; }
/** * Sets the price of the car (in euros). * * @param price Car price. */ public void setPrice(double price) { this.price = price; }
/** * Gets the model of the car. * * @return Model of the car. */ public String getModel() { return model; }
/** * Sets the model of the car. * * @param model Model of the car. */ public void setModel(String model) { this.model = model; }
}
</source>