Advertisement
deyanmalinov

01.Car Info - 2

Apr 25th, 2020
461
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.59 KB | None | 0 0
  1. package DPM;
  2. import java.util.Scanner;
  3. import java.util.stream.IntStream;
  4. public class Main {
  5.     public static void main(String[] args) {
  6.         Scanner scan = new Scanner(System.in);
  7.         int num = Integer.parseInt(scan.nextLine());
  8.         IntStream
  9.                 .rangeClosed(1, num)
  10.                 .boxed()
  11.                 .map(n -> scan.nextLine().split(" "))
  12.                 .map(data ->{
  13.             Car newCar = new Car();
  14.             newCar.setMake(data[0]);
  15.             newCar.setModel(data[1]);
  16.             newCar.setHorsePower(Integer.parseInt(data[2]));
  17.             return newCar;
  18.         })
  19.                 .forEach(car -> System.out.println(car.getCarInfo()));
  20.     }
  21. }
  22. ------------------------------------------------------------------------------
  23. ------------------------------------------------------------------------------
  24. package DPM;
  25. public class Car {
  26.         private String make;
  27.         public String getMake() {
  28.         return make;
  29.     }
  30.     public void setMake(String make) {
  31.         this.make = make;
  32.     }
  33.     public String getModel() {
  34.         return model;
  35.     }
  36.     public void setModel(String model) {
  37.         this.model = model;
  38.     }
  39.     public int getHorsePower() {
  40.         return horsePower;
  41.     }
  42.     public void setHorsePower(int horsePower) {
  43.         this.horsePower = horsePower;
  44.     }
  45.     private String model;
  46.         private int horsePower;
  47.         public String getCarInfo(){
  48.             return String.format("The car is: %s %s - %d HP.",
  49.                     this.getMake(), this.getModel(), this.getHorsePower());
  50.         }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement