Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Практическая работа No1. #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
MorzMorz wants to merge 5 commits into main
base: main
Choose a base branch
Loading
from master
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion settings.gradle
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ dependencyResolutionManagement {
mavenCentral()
}
}
rootProject.name = "BillCalculator"
rootProject.name = "Java-Module-Project"
22 changes: 0 additions & 22 deletions src/main/java/Calculator.java
View file Open in desktop

This file was deleted.

17 changes: 0 additions & 17 deletions src/main/java/Formatter.java
View file Open in desktop

This file was deleted.

10 changes: 0 additions & 10 deletions src/main/java/Item.java
View file Open in desktop

This file was deleted.

75 changes: 43 additions & 32 deletions src/main/java/Main.java
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,58 @@
public class Main {

public static void main(String[] args) {
Race race = new Race();
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("Введите название " + (i + 1) + " автомобиля: ");

String nameCar = scanner.next();

int speedCar;
while (true) {
System.out.println("Введите скорость " + (i + 1) + "-го автомобиля (от 0 до 250 км/час): ");
if (scanner.hasNextInt()) {
speedCar = scanner.nextInt();
if (speedCar >= 0 && speedCar <= 250) {
break;
} else {
System.out.println("Недопустимая скорость автомобиля. Попробуйте еще раз.");
}
} else {
System.out.println("Упс! Ошибка! Введите скорость цифрами.");
scanner.next();
}
}
}

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();
RacingCar racingCar = new RacingCar(nameCar, speedCar);
race.newLeader(racingCar);
}
System.out.println("Победил автомобиль: " + race.winnerCar);
}
}

calculator.addItem(new Item(name, price));

System.out.println(
"Хотите добавить еще один товар? Введите любой символ для продолжения, либо 'Завершить' если больше нет товаров для добавления");
String answer = scanner.next();
class Race {
String winnerCar = "";
int distance = 0;

if (answer.equalsIgnoreCase("Завершить")) {
break;
}
public void newLeader(RacingCar racingCar){
int carDistance = 24 * racingCar.speed;
if (carDistance > distance){
winnerCar = racingCar.name;
distance = carDistance;
}
}
}


double result = calculator.divideSum();
Formatter formatter = new Formatter();
class RacingCar {
String name;
int speed;

System.out.println(calculator.cart);
System.out.println("Каждому человеку к оплате: " + formatter.roundResult(result) + " " + formatter.formatValue(result));
public RacingCar(String name, int speed) {
this.name = name;
this.speed = speed;
}
}

AltStyle によって変換されたページ (->オリジナル) /