Advertisement
Guest User

main

a guest
Oct 15th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. package SpeedRacing_03;
  2.  
  3. import java.util.LinkedHashMap;
  4. import java.util.Map;
  5. import java.util.Scanner;
  6.  
  7. public class Main {
  8. public static void main(String[] args) {
  9. Scanner scanner = new Scanner(System.in);
  10.  
  11. Map<String, Car> garage = new LinkedHashMap<>();
  12.  
  13. int n = Integer.parseInt(scanner.nextLine());
  14.  
  15. while (n-- > 0) {
  16. String[] tokens = scanner.nextLine().split(" ");
  17. String model = tokens[0];
  18. double fuel = Double.parseDouble(tokens[1]);
  19. double consumption = Double.parseDouble(tokens[2]);
  20. Car car = new Car(model, fuel, consumption);
  21. }
  22. String line = scanner.nextLine();
  23. while (!line.equals("End")) {
  24. String[] data = line.split("\\s+");
  25.  
  26. String model = data[1];
  27. double distance = Double.parseDouble(data[2]);
  28.  
  29. if (garage.get(model).drive(distance)) {
  30. System.out.println("Insufficient fuel for the drive");
  31. }
  32.  
  33. line = scanner.nextLine();
  34. }
  35. garage.entrySet().stream().forEach(entry -> {
  36. System.out.println(String.format("%s %.2f %d", entry.getKey(), entry.getValue().getFuel(), entry.getValue().getDistanceTraveled()));
  37. });
  38.  
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement