-
Notifications
You must be signed in to change notification settings - Fork 220
Hometask1 Sitnikov #163
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
Open
Hometask1 Sitnikov #163
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
22 changes: 0 additions & 22 deletions
src/main/java/Calculator.java
Oops, something went wrong.
17 changes: 0 additions & 17 deletions
src/main/java/Formatter.java
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
src/main/java/Item.java
Oops, something went wrong.
103 changes: 74 additions & 29 deletions
src/main/java/Main.java
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,94 @@ | ||
| import java.util.Scanner; | ||
| import java.util.InputMismatchException; | ||
|
|
||
|
|
||
| public class Main { | ||
|
|
||
| public static void main(String[] args) { | ||
|
|
||
| Race race = new Race(); | ||
|
|
||
| System.out.println("Welcome to Le-Man 24"); | ||
| 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("Неверное количество друзей. Значение должно быть болье единицы, давайте попробуем еще раз."); | ||
| for (int i = 0; i <3; i++) { | ||
| System.out.println("Enter the name of the vehicle # " + (i+1)); | ||
| String name = scanner.next(); | ||
|
|
||
| int maxSpeed; | ||
| do { | ||
| try { | ||
| System.out.println("Enter the max speed of the vehicle " + name + " (1 - 250 km/h)"); | ||
| maxSpeed = scanner.nextInt(); | ||
| if (maxSpeed <= 0 || maxSpeed > 0) { | ||
| System.out.println("The speed must be within 1 - 250 km/h range"); | ||
| } | ||
| } catch(InputMismatchException j) { | ||
| System.out.println("Error. Enter the correct speed within 1 - 250 km/h"); | ||
| scanner.next(); | ||
| maxSpeed = 0; | ||
| } | ||
|
|
||
|
|
||
| } | ||
| while (maxSpeed <= 0 || maxSpeed > 250); | ||
|
|
||
| Vehicle vehicle = new Vehicle(name, maxSpeed); | ||
| race.determineTheChampion(vehicle); | ||
| } | ||
|
|
||
| Calculator calculator = new Calculator(friendCount); | ||
| Vehicle theChampion = race.announceTheChampion(); | ||
| System.out.println(" The Champion of Le-Man 24 is " + theChampion.getName()); | ||
| } | ||
| } | ||
|
|
||
| while (true) { | ||
| System.out.println("Введите название товара"); | ||
| String name = scanner.next(); | ||
| // ваш код начнется здесь | ||
| // вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости | ||
|
|
||
| System.out.println("Введите стоимость товара в формате: 'рубли.копейки' [10.45, 11.40]"); | ||
| double price = scanner.nextDouble(); | ||
| class Vehicle { | ||
|
|
||
| calculator.addItem(new Item(name, price)); | ||
| private String name; | ||
| private int maxSpeed; | ||
|
|
||
| System.out.println( | ||
| "Хотите добавить еще один товар? Введите любой символ для продолжения, либо 'Завершить' если больше нет товаров для добавления"); | ||
| String answer = scanner.next(); | ||
| public Vehicle(String name, int maxSpeed) { | ||
| this.name = name; | ||
| this.maxSpeed = maxSpeed; | ||
| } | ||
|
|
||
| public String getName() { | ||
|
|
||
| return name; | ||
| } | ||
|
|
||
| public int getMaxSpeed() { | ||
|
|
||
| return maxSpeed; | ||
| } | ||
|
|
||
| } | ||
|
|
||
|
|
||
| class Race { | ||
| public Vehicle theChampion; | ||
|
|
||
| public Race() { | ||
| this.theChampion = null; | ||
| } | ||
|
|
||
| public void determineTheChampion(Vehicle vehicle) { | ||
|
|
||
| int theLongestDistance = vehicle.getMaxSpeed() * 24; | ||
| System.out.println("Vehicle " + vehicle.getName() + " runs " + theLongestDistance + " km for 24 hours"); | ||
| if (theChampion == null || vehicle.getMaxSpeed() > theChampion.getMaxSpeed()) { | ||
|
|
||
| theChampion = vehicle; | ||
|
|
||
| if (answer.equalsIgnoreCase("Завершить")) { | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| double result = calculator.divideSum(); | ||
| Formatter formatter = new Formatter(); | ||
| } | ||
|
|
||
| System.out.println(calculator.cart); | ||
| System.out.println("Каждому человеку к оплате: " + formatter.roundResult(result) + " " + formatter.formatValue(result)); | ||
| public Vehicle announceTheChampion() { | ||
| return theChampion; | ||
| } | ||
| } | ||
|
|
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.