Advertisement
Guest User

VehicleCatalogue

a guest
Nov 11th, 2018
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.23 KB | None | 0 0
  1. package classesAndObjects;
  2.  
  3. import java.util.*;
  4.  
  5. public class vehicleCatalogue {
  6.     public static void main(String[] args){
  7.         Scanner scanner = new Scanner(System.in);
  8.         String line = scanner.nextLine();
  9.  
  10.         Map<String,List<Vehicle>> vehicle = new LinkedHashMap<>();
  11.  
  12.         while(!line.equals("End")){
  13.             String[] input = line.split(" ");
  14.             Vehicle v = new Vehicle(input[1],input[2],Integer.parseInt(input[3]));
  15.             switch(input[0]){
  16.                 case"truck":
  17.                     if(!vehicle.containsKey(input[0])){
  18.                         vehicle.put(input[0],new ArrayList<>());
  19.                         vehicle.get(input[0]).add(v);
  20.                     }else{
  21.                         vehicle.get(input[0]).add(v);
  22.                     }
  23.                     break;
  24.                 case"car":
  25.                     if(!vehicle.containsKey(input[0])){
  26.                         vehicle.put(input[0],new ArrayList<>());
  27.                         vehicle.get(input[0]).add(v);
  28.                     }else{
  29.                         vehicle.get(input[0]).add(v);
  30.                     }
  31.  
  32.             }
  33.             line = scanner.nextLine();
  34.         }
  35.  
  36.         List<Vehicle> vehicleCharacteristics = vehicle.get();
  37.         String lineTwo = scanner.nextLine();
  38.         while(!lineTwo.equals("Close the Catalogue")){
  39.             String input = lineTwo;
  40.             for(Vehicle vh : vehicleCharacteristics){
  41.  
  42.                 if(vh.getBrand().equals(input)){
  43.                     System.out.println(vh.toString());
  44.                 }
  45.             }
  46.  
  47.             line = scanner.nextLine();
  48.         }
  49.     }
  50. }
  51. class Vehicle{
  52.     private String brand;
  53.     private String color;
  54.     private int horsepower;
  55.  
  56.     public Vehicle(String b, String c, int h){
  57.         this.brand = b;
  58.         this.color = c;
  59.         this.horsepower = h;
  60.     }
  61.     public String getBrand(){
  62.         return  this.brand;
  63.     }
  64.     public String getColor(){
  65.         return  this.color;
  66.     }
  67.     public int getHoserpower(){
  68.         return this.horsepower;
  69.     }
  70. @Override
  71.    public  String toString(){
  72.         return String.format("Model: %s%nColor: %s%nHorsepower: %s%n",getBrand(),getColor(),getHoserpower());
  73. }
  74.  
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement