Advertisement
deyanmalinov

3. Car Shop Extend

Jul 8th, 2020
894
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.32 KB | None | 0 0
  1. package DPM;
  2. import java.util.Scanner;
  3. public class Main {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         Sellable seat = new Seat("Leon", "gray", 110, "Spain", 11111.1);
  7.         Rentable audi = new Audi("Leon", "gray", 110, "Spain", 3, 99.9);
  8.         System.out.println(seat.toString());
  9.         System.out.println(audi.toString());
  10.     }
  11. }------------------------------------------
  12. package DPM;
  13. public interface Car {
  14.     int TIRES = 4;
  15.     String getModel();
  16.     String getColor();
  17.     Integer getHorsePower();
  18. }------------------------------------------
  19. package DPM;
  20. public interface Sellable extends Car{
  21.     Double getPrice();
  22. }------------------------------------------
  23. package DPM;
  24. public interface Rentable extends Car{
  25.     Integer getMinRentDay();
  26.     Double getPricePerDay();
  27. }------------------------------------------
  28. package DPM;
  29. public class Seat implements Sellable {
  30.     private String countryProduced;
  31.     private String model;
  32.     private String color;
  33.     private Integer horsePower;
  34.     private Double price;
  35.     public Seat(String model, String color, Integer horsePower,String countryProduced, Double price){
  36.         this.countryProduced=countryProduced;
  37.         this.model=model;
  38.         this.color=color;
  39.         this.horsePower=horsePower;
  40.         this.price=price;
  41.     }
  42.     @Override
  43.     public String getModel() {
  44.         return model;
  45.     }
  46.     @Override
  47.     public String getColor() {
  48.         return color;
  49.     }
  50.     @Override
  51.     public Integer getHorsePower() {
  52.         return horsePower;
  53.     }
  54.     @Override
  55.     public Double getPrice() {
  56.         return price;
  57.     }
  58.     @Override
  59.     public String toString() {
  60.         return String.format("%s is %s and have %d horse powers\nThis is %s produced in %s and have %d tires",
  61.                 this.getModel(), this.getColor(), this.getHorsePower(), this.getModel(), this.countryProduced, TIRES);
  62.     }
  63. }-------------------------------------------------------------
  64. package DPM;
  65. public class Audi implements Rentable {
  66.     private String countryProduced;
  67.     private String model;
  68.     private String color;
  69.     private Integer horsePower;
  70.     private Integer minRentDay;
  71.     private Double pricePerDay;
  72.     public Audi(String model, String color, Integer horsePower,String countryProduced,
  73.                 Integer minRentDay, Double pricePerDay) {
  74.         this.countryProduced = countryProduced;
  75.         this.model = model;
  76.         this.color = color;
  77.         this.horsePower = horsePower;
  78.         this.minRentDay= minRentDay;
  79.         this.pricePerDay=pricePerDay;
  80.     }
  81.     @Override
  82.     public Integer getMinRentDay() {
  83.         return minRentDay;
  84.     }
  85.     @Override
  86.     public Double getPricePerDay() {
  87.         return pricePerDay;
  88.     }
  89.  
  90.     @Override
  91.     public String getModel() {
  92.         return model;
  93.     }
  94.  
  95.     @Override
  96.     public String getColor() {
  97.         return color;
  98.     }
  99.  
  100.     @Override
  101.     public Integer getHorsePower() {
  102.         return horsePower;
  103.     }
  104.     @Override
  105.     public String toString() {
  106.         return String.format("%s is %s and have %d horse powers\nThis is %s produced in %s and have %d tires",
  107.                 this.getModel(), this.getColor(), this.getHorsePower(), this.getModel(), this.countryProduced, TIRES);
  108.     }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement