Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- public class CarProblem
- {
- public static void Main()
- {
- int[] carInfo = Console.ReadLine().Split().Select(int.Parse).ToArray();
- int speed = carInfo[0];
- int fuel = carInfo[1];
- int fuelEconomy = carInfo[2];
- var car = new Car(speed, fuel, fuelEconomy);
- string input = Console.ReadLine();
- while (input != "END")
- {
- string[] command = input.Split();
- if (command[0] == "Travel")
- {
- car.Travel(int.Parse(command[1]));
- }
- else if (command[0] == "Refuel")
- {
- car.Refuel(int.Parse(command[1]));
- }
- else if (command[0] == "Distance")
- {
- Console.WriteLine($"Total distance: {car.TotalDistance():f1} kilometers");
- }
- else if (command[0] == "Time")
- {
- Console.WriteLine($"Total time: {car.Hours()} hours and {car.Minutes()} minutes");
- }
- else if (command[0] == "Fuel")
- {
- Console.WriteLine($"Fuel left: {car.RemFuel():f1} liters");
- }
- input = Console.ReadLine();
- }
- }
- public class Car
- {
- public double speed;
- public double fuel;
- public double fuelEconomy;
- public double traveledDistance;
- public Car(double speed, double fuel, double fuelEconomy)
- {
- this.speed = speed;
- this.fuel = fuel;
- this.fuelEconomy = fuelEconomy;
- }
- public void Travel(double distanceToTravel)
- {
- this.traveledDistance = distanceToTravel;
- }
- public void Refuel(double refuelAmount)
- {
- this.fuel += refuelAmount;
- }
- public double TotalDistance()
- {
- return this.traveledDistance;
- }
- public int Hours()
- {
- return (int)(this.traveledDistance / this.speed);
- }
- public double Minutes()
- {
- return (int)(this.traveledDistance % this.speed);
- }
- public double RemFuel()
- {
- return this.fuel - this.fuelEconomy * (this.traveledDistance / this.speed);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement