online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); Car car = Car.get(scanner); while (true) { System.out.println( "Выберете пункт меню:\n" + "0. выход\n" + "1. ехать\n" + "2. заправляться\n" + "3. менять колесо\n" + "4. вывести информацию об авто (марку тоже)\n" + ": " ); int choice = scanner.nextInt(); if (choice == 0) break; if (choice < 1 || choice > 4) { System.out.println("выбран неправильный пункт меню, повторите ввод."); continue; } switch (choice) { case 1: car.move(); break; case 2: System.out.println("Введи количество топлива:"); double fuel = scanner.nextDouble(); car.add_fuel(fuel); break; case 3: car.change_wheel(scanner); break; case 4: System.out.println(car.toString()); break; } } } }
import java.util.*; class Car { private Wheel wheels[]; private Engine engine; private String brand; private double consumption; private double fuel_level; public Car(String brand_, double consumption_, Engine engine_, Wheel wheels_[], double fuel_level_) { brand = brand_; consumption = consumption; engine = engine_; wheels = wheels_; fuel_level = fuel_level_; } public String toString() { String string = ""; string += brand + engine.toString() + ";" + consumption + "L/100km { " + fuel_level + "}; ["; for (int i = 0; i < 4; ++i) { string += wheels[i].toString() + " "; } return string + "]"; } public static Car get(Scanner scanner) { Car object = new Car("", 0, new Engine(0,0), new Wheel[4], 0); System.out.print("Введи марку автомобиля: "); object.brand = Common.readNotEmptyString(scanner); System.out.print("Введи расход топлива на 100км: "); object.consumption = scanner.nextDouble(); System.out.print("Введи текущий уровень топлива:"); object.fuel_level = scanner.nextDouble(); System.out.println("Введи колеса:"); for (int i = 0; i < 4; ++i) { System.out.println("колесо #" + i); object.wheels[i] = Wheel.get(scanner); } object.engine = Engine.get(scanner); return object; } public void move() { if (fuel_level <= 0) { System.out.println("Нет бензина, машина не может двигаться"); return; } for (int i = 1; i < 4; ++i) { if (wheels[i].get_diameter() != wheels[i-1].get_diameter()) { System.out.println("Колеса разных диаметров, машина не может двигаться"); return; } } double distance = fuel_level/consumption; System.out.println("машина проехала " + distance*100 + "км."); fuel_level = 0; } public void add_fuel(double value) { fuel_level += value; } public void change_wheel(Scanner scanner) { System.out.println("Введи номер колеса [0-3]:"); int number; while (true) { number = scanner.nextInt(); if (number >= 0 && number <= 3) break; System.out.println("Неправильный номер, повтори ввод"); } wheels[number] = Wheel.get(scanner); } }
import java.util.Scanner; class Common { public static String readNotEmptyString(Scanner scanner) { String string = ""; while (string.length() == 0) { string = scanner.nextLine(); } return string; } }
import java.util.*; class Wheel { public enum Type { Winter, Summer } private double diameter; private String brand; private Type type; public Wheel(String brand_, double diameter_, Type type_) { brand = brand_; diameter = diameter_; type = type_; } public String toString() { String string = ""; string += brand + "(" + diameter + "): "; if (type == Type.Winter) string += "Winter"; else string += "Summer"; return string; } public static Wheel get(Scanner scanner) { Wheel object = new Wheel("", 0, Type.Winter); System.out.print("Введи бренд: "); object.brand = Common.readNotEmptyString(scanner); System.out.print("Введи диаметр: "); object.diameter = scanner.nextDouble(); System.out.print("Введи тип (1) - зимние, (2) - летние: "); while (true) { int value = scanner.nextInt(); if (value == 1) { object.type = Type.Winter; break; } if (value == 2) { object.type = Type.Summer; break; } System.out.print("Введено неправильное значение, повтори ввод."); } return object; } public double get_diameter() { return diameter; } }
import java.util.*; class Engine { private int number; private double power; public Engine(int number_, double power_) { number = number_; power = power_; } public String toString() { String string = "engine: " + number + ", power:" + power; return string; } public static Engine get(Scanner scanner) { Engine object = new Engine(0,0); System.out.print("Введи номер двигателя: "); object.number = scanner.nextInt(); System.out.print("Введи мощность двигателя: "); object.power = scanner.nextDouble(); return object; } }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue