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

Проект #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
Shahidow wants to merge 2 commits into main
base: main
Choose a base branch
Loading
from dev
Open
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
84 changes: 81 additions & 3 deletions src/main/java/Main.java
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -1,6 +1,84 @@

import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
System.out.println("На скольких человек необходимо разделить счёт?");
while(true) {
Scanner sc = new Scanner(System.in);
if(sc.hasNextInt()) {
int qty = sc.nextInt();
if (qty>1) {
Calculator unit = new Calculator();
unit.qty = qty;
unit.input();
break;
}
}
System.out.println("Ошибка! Повторите ввод!");
}
}
}
}
class Calculator{
Copy link

@kirillNay kirillNay Jun 4, 2023

Choose a reason for hiding this comment

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

⏫ Желательно все классы держать в разных файлах, чтобы было проще ориентироваться внутри одного файла

ArrayList<String> list = new ArrayList<>();
int qty;
double price=0;

private double price() {
double inputPrice;
while(true){
Scanner sc = new Scanner(System.in);
if(!sc.hasNextDouble()) {
System.out.println("Ошибка! Не числовое значение! Повторите ввод!");
} else {
inputPrice = sc.nextDouble();
if(inputPrice<=0) {
System.out.println("Ошибка! Некорректная цена! Повторите ввод!");
} else {
price += inputPrice;
break;
}
}
}
return price;
}

private String declension(double sum) {
sum = Math.floor(sum);
for(int i=11; i<=14; i++) {
if ((sum - i) % 100 == 0) {
return " рублей.";
}
}
if(sum%10 ==1) {
return " рубль.";
} else if(sum%10 ==2 || sum%10==3 || sum%10== 4) {
return " рубля.";
}
return " рублей.";
}

public void input() {
double inputSum, sum;
while(true) {
Scanner sc = new Scanner(System.in);
System.out.println("Введите название товара:");
String product = sc.nextLine();
System.out.println("Введите цену товара:");
inputSum = price();
list.add(product);
System.out.println("Товар добавлен!\nХотите добавить ещё один товар?");
String answer = sc.next();
if (answer.equalsIgnoreCase("завершить")) {
break;
}
}
System.out.println("Добавленные товары:");
for(int i=0; i<list.size(); i++){
System.out.println(list.get(i));
}
sum = inputSum/qty;
String rub = declension(sum);
String result = String.format("%.2f", sum);
System.out.println("Счет на каждого человека: " + result + rub);
}
}

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