-
Notifications
You must be signed in to change notification settings - Fork 0
Dev #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Dev #1
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,49 +1,79 @@ | ||
| import java.util.ArrayList; | ||
| import java.util.Scanner; | ||
|
|
||
| public class Main { | ||
|
|
||
| public static void main(String[] args) { | ||
| Scanner scanner = new Scanner(System.in); | ||
|
|
||
| int friendCount; | ||
| while (true) { | ||
| System.out.println("На сколько человек необходимо разделить счет?"); | ||
| friendCount = scanner.nextInt(); | ||
|
|
||
| if (friendCount > 1) { | ||
| ArrayList<Car> cars = new ArrayList<>(); | ||
| System.out.println("Введите название машины №1:"); | ||
| String nameCar = scanner.next(); | ||
| while(true){ | ||
| System.out.println("Введите скорость машины " + nameCar+" :"); | ||
| int speedCar = scanner.nextInt(); | ||
| Car car = new Car(nameCar, speedCar); | ||
| if(car.speed>0&&car.speed<251){ | ||
| cars.add(car); | ||
| System.out.println(car.name + " подходит! Она проедет "+ leMan(car.speed) +" за 24 часа."); | ||
| break; | ||
| } else if (friendCount == 1) { | ||
| System.out.println( | ||
| "Нет смысла делить сумму на одного человека. Давайте попробуем ввести другое значение, которое будет больше единицы."); | ||
| } else { | ||
| System.out.println("Неверное количество друзей. Значение должно быть болье единицы, давайте попробуем еще раз."); | ||
| }else{ | ||
| System.out.println("Машина не подходит на гонку допускаются машины со скоростью до 250 км/ч. Попробуйте еще раз, так как скорость "+ car.name +" = "+ car.speed +" км/ч."); | ||
| } | ||
| } | ||
|
|
||
| Calculator calculator = new Calculator(friendCount); | ||
|
|
||
| while (true) { | ||
| System.out.println("Введите название товара"); | ||
| String name = scanner.next(); | ||
|
|
||
| System.out.println("Введите стоимость товара в формате: 'рубли.копейки' [10.45, 11.40]"); | ||
| double price = scanner.nextDouble(); | ||
|
|
||
| calculator.addItem(new Item(name, price)); | ||
|
|
||
| System.out.println( | ||
| "Хотите добавить еще один товар? Введите любой символ для продолжения, либо 'Завершить' если больше нет товаров для добавления"); | ||
| String answer = scanner.next(); | ||
|
|
||
| if (answer.equalsIgnoreCase("Завершить")) { | ||
| System.out.println("Введите название машины №2:"); | ||
| String nameCar2 = scanner.next(); | ||
| while(true){ | ||
| System.out.println("Введите скорость машины "+ nameCar2); | ||
| int speedCar2 = scanner.nextInt(); | ||
| Car car2 = new Car(nameCar2, speedCar2); | ||
| if(car2.speed>0&&car2.speed<251){ | ||
| cars.add(car2); | ||
| System.out.println(car2.name + " подходит! Она проедет "+ leMan(car2.speed) +" км за 24 часа."); | ||
| break; | ||
| }else{ | ||
| System.out.println("Машина не подходит на гонку допускаются машины со скоростью до 250 км/ч. Попробуйте еще раз, так как скорость "+ car2.name +" = "+ car2.speed +" км/ч."); | ||
| } | ||
| } | ||
|
|
||
| double result = calculator.divideSum(); | ||
| Formatter formatter = new Formatter(); | ||
|
|
||
| System.out.println(calculator.cart); | ||
| System.out.println("Каждому человеку к оплате: " + formatter.roundResult(result) + " " + formatter.formatValue(result)); | ||
| System.out.println("Введите название машины №3:"); | ||
| String nameCar3 = scanner.next(); | ||
| while(true){ | ||
| System.out.println("Введите скорость машины "+ nameCar3); | ||
| int speedCar3 = scanner.nextInt(); | ||
| Car car3 = new Car(nameCar3, speedCar3); | ||
| if(car3.speed>0&&car3.speed<251){ | ||
| cars.add(car3); | ||
| System.out.println(car3.name + " подходит! Она проедет "+ leMan(car3.speed) +" км за 24 часа."); | ||
| break; | ||
| }else{ | ||
| System.out.println("Машина не подходит на гонку допускаются машины со скоростью до 250 км/ч. Попробуйте еще раз, так как скорость "+ car3.name +" = "+ car3.speed +" км/ч."); | ||
| } | ||
|
Comment on lines
+61
to
79
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Общий код лучше выносить в отдельные функции. Сейчас у тебя копируется код, который считывает и валидирует каждую из машин, этот код можно обобщить в одной функции и использовать её в трёх местах |
||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Этот кусок кода повторяется три раза, его можно вынести в отдельную функцию |
||
| if(cars.get(0).speed>cars.get(1).speed&&cars.get(0).speed>cars.get(2).speed){ | ||
| System.out.println("Самая быстрая машина: " + cars.get(0).name); | ||
| }else if(cars.get(1).speed>cars.get(0).speed&&cars.get(1).speed>cars.get(2).speed){ | ||
| System.out.println("Самая быстрая машина: " + cars.get(1).name); | ||
| }else if(cars.get(2).speed>cars.get(0).speed&&cars.get(2).speed>cars.get(1).speed){ | ||
| System.out.println("Самая быстрая машина: " + cars.get(2).name); | ||
| }else if(cars.get(0).speed==cars.get(1).speed&&cars.get(0).speed>cars.get(2).speed){ | ||
| System.out.println("Самые быстрые машины: " + cars.get(0).name+", "+cars.get(1).name); | ||
| }else if(cars.get(1).speed==cars.get(2).speed&&cars.get(1).speed>cars.get(0).speed) { | ||
| System.out.println("Самые быстрые машины: " + cars.get(1).name + ", " + cars.get(2).name); | ||
| }else if(cars.get(0).speed==cars.get(2).speed&&cars.get(1).speed>cars.get(1).speed) { | ||
| System.out.println("Самые быстрые машины: " + cars.get(0).name + ", " + cars.get(2).name); | ||
| } else{ | ||
| System.out.println("Все машины финишируют одинаково"); | ||
| } | ||
|
Comment on lines
+81
to
+95
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Это бы тоже вынести в отдельную функцию и можно написать проще, т.к. такой многоэтажный if очень тяжело читать и понимать. В списке хранится скорость каждой из машин, которую можно умножить на 24 и вывести индекс того элемента списка, у которого получившееся значение выше остальных |
||
| } | ||
| public static int leMan(int speeds){ | ||
| int speedCar = speeds*24; | ||
| return speedCar; | ||
| } | ||
| } | ||
| class Car{ | ||
| String name; | ||
| int speed; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Эти переменные лучше пометить final |
||
| public Car(String name, int speed){ | ||
| this.name = name; | ||
| this.speed = speed; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Лучше вынести в константы минимальную и максимальную скорость