ITI0011-2016:harjutus 10 lihtsam

Allikas: Kursused
Mine navigeerimisribale Mine otsikasti

Ü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 on null, siis tagastab null. Auto müümisel peab selle hind olema 10% kallim (ehk siis objekt, mis tagastatakse, peab olema 10% suurema hinnaga).
  • getAmount tagastab etteantud mudeliga autode koguse poes. Kui etteantud mudel on null, 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>