Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.zdr;
- import java.util.*;
- public class Main {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- List<Car> cars = new ArrayList<>();
- int numberOfCars = Integer. parseInt(input.nextLine());
- for(int i=0; i<numberOfCars; i++) {
- String[] currentCarInfo = input.nextLine().split(" ");
- String model = currentCarInfo[0];
- int fuelAmount = Integer.parseInt(currentCarInfo[1]);
- double fuelCostPerKm = Double.parseDouble(currentCarInfo[2]);
- int distanceTravelled = 0;
- Car currentCar = new Car(model, fuelAmount, fuelCostPerKm, distanceTravelled);
- cars.add(currentCar);
- }
- while(true) {
- String[] command = input.nextLine().split(" ");
- if(command[0].equals("End")) break;
- if(command[0].equals("Drive")) {
- String model = command[1];
- int distance = Integer.parseInt(command[2]);
- for(int i=0; i<cars.size(); i++) {
- if(cars.get(i).getModel().equals(model)) {
- cars.get(i).canTravelThisDistance(distance);
- }
- }
- }
- }
- for(Car car : cars) {
- System.out.println(String.format("%s %.2f %d", car.getModel(), car.getFuelAmount(), car.getDistanceTraveled()));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement