Advertisement
deyanmalinov

2. Car Shop

Jul 8th, 2020
1,032
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.44 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.         Car seat = new Seat("Leon", "gray", 110, "Spain");
  7.         System.out.println(seat.toString());
  8.     }
  9. }----------------------------------------
  10. package DPM;
  11. public interface Car {
  12.     int TIRES = 4;
  13.     String getModel();
  14.     String getColor();
  15.     Integer getHorsePower();
  16. }--------------------------------------
  17. package DPM;
  18. import java.io.Serializable;
  19. public class Seat implements Car, Serializable {
  20.     private String countryProduced;
  21.     private String model;
  22.     private String color;
  23.     private Integer horsePower;
  24.     public Seat(String model, String color, Integer horsePower,String countryProduced){
  25.         this.countryProduced=countryProduced;
  26.         this.model=model;
  27.         this.color=color;
  28.         this.horsePower=horsePower;
  29.     }
  30.     @Override
  31.     public String getModel() {
  32.         return model;
  33.     }
  34.     @Override
  35.     public String getColor() {
  36.         return color;
  37.     }
  38.     @Override
  39.     public Integer getHorsePower() {
  40.         return horsePower;
  41.     }
  42.     @Override
  43.     public String toString() {
  44.         return String.format("%s is %s and have %d horse powers\nThis is %s produced in %s and have %d tires",
  45.                 this.getModel(), this.getColor(), this.getHorsePower(), this.getModel(), this.countryProduced, TIRES);
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement