Erinevus lehekülje "ITI0011-2016:harjutus 10 lihtsam" redaktsioonide vahel
Mine navigeerimisribale
Mine otsikasti
(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...') |
|||
| 11. rida: | 11. rida: | ||
Realiseerida <code>ExpensiveCarShop</code>, mis implementeerib <code>CarShop</code> liidest. Realiseeritav funktsionaalsus: | Realiseerida <code>ExpensiveCarShop</code>, mis implementeerib <code>CarShop</code> liidest. Realiseeritav funktsionaalsus: | ||
* auto müümisel pannakse selle hinnale 10% otsa. Ehk kui auto hind on 100 eurot, siis <code>sellCar</code> selle auto kohta tagastab 110. | * auto müümisel pannakse selle hinnale 10% otsa. Ehk kui auto hind on 100 eurot, siis <code>sellCar</code> selle auto kohta tagastab 110. | ||
| − | * <code>sellCar</code> tagastab suvalise auto nimetatud mudeliga. Kui mudel on <code>null</code>, siis tagastab | + | * <code>sellCar</code> tagastab suvalise auto nimetatud mudeliga. Kui mudel on <code>null</code>, siis tagastab <code>null</code>. Auto müümisel peab selle hind olema 10% kallim (ehk siis objekt, mis tagastatakse, peab olema 10% suurema hinnaga). |
| + | * <code>getAmount</code> tagastab etteantud mudeliga autode koguse poes. Kui etteantud mudel on <code>null</code>, siis tagastab kõikide autode koguse. | ||
| 32. rida: | 33. rida: | ||
* Car will be removed from the owned cars. | * Car will be removed from the owned cars. | ||
* @param model Car with the specified model is sold. | * @param model Car with the specified model is sold. | ||
| − | * @return | + | * @return Car to be sold. Null if no car with the specified model found. |
| − | |||
*/ | */ | ||
| − | + | Car sellCar(String model); | |
/** | /** | ||
Redaktsioon: 19. märts 2016, kell 04:34
Ü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
sellCarselle auto kohta tagastab 110. sellCartagastab suvalise auto nimetatud mudeliga. Kui mudel onnull, siis tagastabnull. Auto müümisel peab selle hind olema 10% kallim (ehk siis objekt, mis tagastatakse, peab olema 10% suurema hinnaga).getAmounttagastab etteantud mudeliga autode koguse poes. Kui etteantud mudel onnull, siis tagastab kõikide autode koguse.
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 Car to be sold. Null if no car with the specified model found.
*/
Car 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>