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
TelenkovAleksey wants to merge 6 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
3 changes: 3 additions & 0 deletions .idea/.gitignore
View file Open in desktop

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/.name
View file Open in desktop

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

123 changes: 123 additions & 0 deletions .idea/codeStyles/Project.xml
View file Open in desktop

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml
View file Open in desktop

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/compiler.xml
View file Open in desktop

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions .idea/gradle.xml
View file Open in desktop

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/misc.xml
View file Open in desktop

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml
View file Open in desktop

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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"
60 changes: 60 additions & 0 deletions src/main/java/Calculate.java
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import java.util.Scanner;

public class Calculate {

public static void product(double person) {

String food = "";
double price = 0.0;

while (true) {
System.out.println("Для добавления товара введите название продукта\nДля завершения программы введите \"Завершить\"");
Scanner scanner = new Scanner(System.in);
String inputFood = scanner.next();
double itog = 0;

if (inputFood.equalsIgnoreCase("Завершить")) {
itog = (int) (price / person);
System.out.println("Покупка завершена, " + String.format("%.0f", person) + " персоны заплатят по " + itog + " " + Matsh.floover(itog));
break;

} else {
System.out.println("Введите стоимость продукта в формате \"'рубли.копейки' [10.45, 11.40]\"");
while (!scanner.hasNextInt()) {
System.out.println("Некорректное значение, введите стоимость продукта в формате \"'рубли.копейки' [10.45, 11.40]\"");
scanner.next();
}
float inputPrice = (float) scanner.nextDouble();

This comment was marked as resolved.

food = food + "\n" + inputFood;
price = price + inputPrice;

System.out.println("Вы успешно добавили продукт:" + food + "\nИтог: " + String.format("%.2f", price) + " " + Matsh.floover(itog));
Copy link

@MagicUnderHood MagicUnderHood Sep 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Здесь выводится стоимость товара - price, но расчет окончания слова Рубль берется для числа itog, а должна быть одна и та же переменная

Copy link

@MagicUnderHood MagicUnderHood Sep 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Наставница передала твой вопрос, что я имела в виду:
У тебя строка:
System.out.println("Вы успешно добавили продукт:" + food + "\nИтог: " + String.format("%.2f", price) + " " + Matsh.floover(itog));
А должно быть:
System.out.println("Вы успешно добавили продукт:" + food + "\nИтог: " + String.format("%.2f", price) + " " + Matsh.floover(price));
То есть просто ты тут выводишь число в виде переменной price, но в метод, выдающий окончание слова рубль передаешь другую переменную, itog. Из-за этого при выводе стоимости продукта окончание не то получалось

}
}
}

static class Matsh {

public static String floover(double price) {

int amount = (int) price;

if (amount > 100)
amount %= 100;

if (amount > 20)
amount %= 10;

switch (amount) {
case 1:
return "Рублю";
case 2:
case 3:
case 4:
return "Рубля";
default:
return "Рублей";
}
}
}
}
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.

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

This file was deleted.

34 changes: 34 additions & 0 deletions src/main/java/Menu.java
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import java.util.Scanner;

public class Menu {
public static void main(String[] args) {
inputParameters();

}
public static void inputParameters(){
Scanner scanner = new Scanner(System.in);
System.out.println("На сколько персон делить чек?");
int person = 0;

while (!scanner.hasNextInt()) {
System.out.println("Некорректное значение для подсчёта, попробуйте еще раз");
scanner.next();
}
while (true) {
person = scanner.nextInt();
if (person > 1) {
System.out.println("Давайте посчитаем!");
Calculate.product(person);
}
if (person == 1) {
System.out.println("Вы оплачиваете счет сами");
Calculate.product(person);
}
if (person < 1) {
System.out.println("Некорректное значение для подсчёта, попробуйте еще раз");


}
}
}
}

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