Advertisement
desislava_topuzakova

03.SpeedRacing_Main

Oct 5th, 2020
865
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.42 KB | None | 0 0
  1. package SpeedRacing_03;
  2.  
  3. import java.util.LinkedHashMap;
  4. import java.util.Scanner;
  5. import java.util.function.DoubleToIntFunction;
  6.  
  7. public class Main {
  8.     public static void main(String[] args) {
  9.         Scanner scanner = new Scanner (System.in);
  10.         int  n = Integer.parseInt(scanner.nextLine());
  11.         LinkedHashMap<String, Car> cars = new LinkedHashMap<>();
  12.         for (int i = 0; i < n; i++) {
  13.             String [] tokens = scanner.nextLine().split("\\s+");
  14.             String model = tokens[0];
  15.             double fuel = Double.parseDouble(tokens[1]);
  16.             double consumption = Double.parseDouble(tokens[2]);
  17.  
  18.             Car car = new Car(model, fuel, consumption);
  19.             cars.put(model, car);
  20.         }
  21.         String input = scanner.nextLine();
  22.  
  23.         while(!input.equals("End")) {
  24.             //"Drive <CarModel>  <amountOfKm>"
  25.             String model = input.split("\\s+")[1];
  26.             int distanceToDrive = Integer.parseInt(input.split("\\s+")[2]);
  27.             //model -> Car
  28.             Car carToDrive = cars.get(model);
  29.  
  30.             if(!carToDrive.drive(distanceToDrive)) {
  31.                 //не можем да караме
  32.                 System.out.println("Insufficient fuel for the drive");
  33.             }
  34.  
  35.             input = scanner.nextLine();
  36.         }
  37.  
  38.         for (Car car : cars.values()) {
  39.             System.out.println(car.toString());
  40.         }
  41.  
  42.  
  43.  
  44.     }
  45. }
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement