forked from Yandex-Practicum/Java-Module-Project
-
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
Open
VankaGam
wants to merge
4
commits into
main
Choose a base branch
from
dev
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Dev #1
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,49 +1,109 @@ | ||
| 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) { | ||
| break; | ||
| } else if (friendCount == 1) { | ||
| System.out.println( | ||
| "Нет смысла делить сумму на одного человека. Давайте попробуем ввести другое значение, которое будет больше единицы."); | ||
| } else { | ||
| System.out.println("Неверное количество друзей. Значение должно быть болье единицы, давайте попробуем еще раз."); | ||
| ArrayList<Car> cars = new ArrayList<>(); | ||
| System.out.println("Введите название машины №1:"); | ||
| String nameCar = scanner.next(); | ||
| boolean prov = false; | ||
| int speedCar =0; | ||
| while(!prov){ | ||
| System.out.println("Введите скорость машины " + nameCar+" :"); | ||
| try{ | ||
| while(true){ | ||
| 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{ | ||
| System.out.println("Машина не подходит на гонку допускаются машины со скоростью до 250 км/ч. Попробуйте еще раз, так как скорость "+ car.name +" = "+ car.speed +" км/ч."); | ||
| } | ||
| } | ||
| prov = true; | ||
| }catch(Exception exception){ | ||
| System.out.println("Некорректный ввод. Пожалуйста, введите скорость."); | ||
| scanner.nextLine(); | ||
| } | ||
| } | ||
|
|
||
| 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("Завершить")) { | ||
| break; | ||
| System.out.println("Введите название машины №2:"); | ||
| String nameCar2 = scanner.next(); | ||
| boolean prov1 = false; | ||
| int speedCar2 =0; | ||
| while(!prov1){ | ||
| System.out.println("Введите скорость машины " + nameCar2+" :"); | ||
| try{ | ||
| while(true){ | ||
| 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 +" км/ч."); | ||
| } | ||
| } | ||
| prov1 = true; | ||
| }catch(Exception exception){ | ||
| System.out.println("Некорректный ввод. Пожалуйста, введите скорость."); | ||
| scanner.nextLine(); | ||
| } | ||
| } | ||
|
|
||
| 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(); | ||
| boolean prov2 = false; | ||
| int speedCar3 =0; | ||
| while(!prov2){ | ||
| System.out.println("Введите скорость машины " + nameCar3+" :"); | ||
| try{ | ||
| while(true){ | ||
| 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 +" км/ч."); | ||
| } | ||
| } | ||
| prov2 = true; | ||
| }catch(Exception exception){ | ||
| System.out.println("Некорректный ввод. Пожалуйста, введите скорость."); | ||
| scanner.nextLine(); | ||
| } | ||
| } | ||
| 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("Все машины финишируют одинаково"); | ||
| } | ||
| } | ||
| public static int leMan(int speeds){ | ||
| int speedCar = speeds*24; | ||
| return speedCar; | ||
| } | ||
| } | ||
| class Car{ | ||
| final String name; | ||
| final int speed; | ||
| public Car(String name, int speed){ | ||
| this.name = name; | ||
| this.speed = speed; | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Это бы тоже вынести в отдельную функцию и можно написать проще, т.к. такой многоэтажный if очень тяжело читать и понимать. В списке хранится скорость каждой из машин, которую можно умножить на 24 и вывести индекс того элемента списка, у которого получившееся значение выше остальных