Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package classesAndObjects;
- import java.util.*;
- public class vehicleCatalogue {
- public static void main(String[] args){
- Scanner scanner = new Scanner(System.in);
- String line = scanner.nextLine();
- Map<String,List<Vehicle>> vehicle = new LinkedHashMap<>();
- while(!line.equals("End")){
- String[] input = line.split(" ");
- Vehicle v = new Vehicle(input[1],input[2],Integer.parseInt(input[3]));
- switch(input[0]){
- case"truck":
- if(!vehicle.containsKey(input[0])){
- vehicle.put(input[0],new ArrayList<>());
- vehicle.get(input[0]).add(v);
- }else{
- vehicle.get(input[0]).add(v);
- }
- break;
- case"car":
- if(!vehicle.containsKey(input[0])){
- vehicle.put(input[0],new ArrayList<>());
- vehicle.get(input[0]).add(v);
- }else{
- vehicle.get(input[0]).add(v);
- }
- }
- line = scanner.nextLine();
- }
- List<Vehicle> vehicleCharacteristics = vehicle.get();
- String lineTwo = scanner.nextLine();
- while(!lineTwo.equals("Close the Catalogue")){
- String input = lineTwo;
- for(Vehicle vh : vehicleCharacteristics){
- if(vh.getBrand().equals(input)){
- System.out.println(vh.toString());
- }
- }
- line = scanner.nextLine();
- }
- }
- }
- class Vehicle{
- private String brand;
- private String color;
- private int horsepower;
- public Vehicle(String b, String c, int h){
- this.brand = b;
- this.color = c;
- this.horsepower = h;
- }
- public String getBrand(){
- return this.brand;
- }
- public String getColor(){
- return this.color;
- }
- public int getHoserpower(){
- return this.horsepower;
- }
- @Override
- public String toString(){
- return String.format("Model: %s%nColor: %s%nHorsepower: %s%n",getBrand(),getColor(),getHoserpower());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement