-
Notifications
You must be signed in to change notification settings - Fork 0
Проектная работа 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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import java.util.Scanner; | ||
|
|
||
| public class Calculator { | ||
| double Calculator() { | ||
|
|
||
| boolean restart = true; | ||
| String chek = " ", menu = " ", stop = "Завершить"; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⏫ Обычно в нейминге переменных используются английские слова:
|
||
| double obshag = 0, many; | ||
| System.out.print("Введите название товара: "); | ||
| while (restart) { | ||
| Scanner scanner = new Scanner(System.in); | ||
| menu = scanner.next(); | ||
| System.out.print("Введите стоймость: "); | ||
| if (menu.equalsIgnoreCase(stop)) { | ||
| restart = false; | ||
| } else if (scanner.hasNextDouble()) { | ||
| many = scanner.nextDouble(); | ||
| if (many >= 0) { | ||
| System.out.print("Продолжить Заказ(Введите название товара)/Завершить счёт(Введите завершить): "); | ||
| chek = chek + "\n" + String.format("%s - %.2f", menu, many); | ||
| obshag += many; | ||
| } else { | ||
| System.out.print("Скидок нету. Цена не должна быть меньше 0:\nВведите название товара: "); | ||
| } | ||
| } else { | ||
| System.out.print("Цена товара не может быть символом!\nВведите название товара: "); | ||
| } | ||
| } | ||
| System.out.println("\nДобавленные товары: "); | ||
| System.out.println(chek); | ||
| System.out.printf("Итого: %.2f", obshag); | ||
| return obshag; | ||
|
|
||
| } | ||
|
|
||
| } | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import java.util.Scanner; | ||
|
|
||
| public class Friends { | ||
|
|
||
| boolean restart = true; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⏫ Переменная |
||
|
|
||
|
|
||
| int friends() { | ||
| System.out.print("На скольких разделить счёт:\t "); | ||
| int result = 0; | ||
| while (restart) { | ||
|
|
||
| Scanner numberFriends = new Scanner(System.in); | ||
| if (numberFriends.hasNextInt()) { | ||
| int number = numberFriends.nextInt(); | ||
| if (number <=1 ){ | ||
| System.out.print("Количество человек, равно 1. В этом случае нет смысла ничего считать и делить.\nВведите сколько вас гостей: "); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⏫ Комментарий по выводимому тексту пользователю: мы не уверены, что он ввел именно 1. Он также мог ввести 0 или отрицательное число |
||
| } else { | ||
| System.out.println("Счёт будет поделён между " + number + " человек. "); | ||
| restart = false; | ||
| result = number; | ||
|
|
||
| } | ||
| } else { | ||
| System.out.print("Вы не ввели число, введите колличество гостей: "); | ||
| } | ||
|
|
||
|
|
||
| } | ||
| return result; | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,17 @@ | ||
|
|
||
| public class Main { | ||
|
|
||
| public static void main(String[] args) { | ||
| System.out.println("Hello world!"); | ||
| Result theEnd = new Result(); | ||
| theEnd.Finish(); | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| } | ||
|
|
||
| } | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| public class Result { | ||
| Calculator menuMany = new Calculator(); | ||
| Friends kolVoPeople = new Friends(); | ||
| double Finish(){ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⏫ Лучше стараться называть все функции с маленькой буквы, такой принцип нейминга общепринятый в java и kotlin |
||
| double zrachKa,peOple,reShala,celoe; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⏫ Также при нейминг переменных лучше придерживаться |
||
| int proverKa, ostatok; | ||
| peOple = kolVoPeople.friends(); | ||
| zrachKa = menuMany.Calculator(); | ||
| System.out.print("\n"); | ||
| reShala = zrachKa / peOple; | ||
| proverKa = (int)Math.floor(reShala); | ||
| ostatok = proverKa%10; | ||
|
|
||
| celoe = ((proverKa - ostatok)/10)%10; | ||
|
|
||
|
|
||
| if (celoe == 1) { | ||
| System.out.printf("С каждого человека пo: %.2f рублей\n", reShala); | ||
| } else { | ||
| if (ostatok == 1 ){ | ||
| System.out.printf("С каждого человека пo: %.2f рубль\n", reShala); | ||
| } | ||
| else if (ostatok > 1 && ostatok < 5 ){ | ||
| System.out.printf("С каждого человека пo: %.2f рубля\n", reShala); | ||
| }else { | ||
| System.out.printf("С каждого человека пo: %.2f рублей\n", reShala); | ||
| } | ||
|
|
||
|
|
||
| } | ||
|
|
||
|
|
||
|
|
||
| return reShala; | ||
|
|
||
|
|
||
|
|
||
|
|
||
| } | ||
|
|
||
|
|
||
|
|
||
| } | ||
|
|
||
|
|
||
| /* double i = 4; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⏫ Лучше в итоговой версии удалять закомментированный код и лишние отступы |
||
|
|
||
| int f = (int) Math.floor(i); | ||
| int result = f%10; | ||
|
|
||
| if(result == 1){ | ||
| System.out.println("Рубль"); | ||
| } else if (result > 1 && result < 5){ | ||
| System.out.println("Рубля"); | ||
| } | ||
|
|
||
| */ | ||