-
Notifications
You must be signed in to change notification settings - Fork 218
Final version. Cosmetic changes2 #115
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 |
|---|---|---|
| @@ -1,8 +1,35 @@ | ||
| import java.util.Scanner; | ||
|
|
||
| public class Main { | ||
|
|
||
| public static void main(String[] args) { | ||
| // ваш код начнется здесь | ||
| // вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости | ||
| System.out.println("Привет Мир"); | ||
| int numberOfFriends; | ||
|
|
||
| System.out.println("Программа \"Калькулятор счёта\""); | ||
| numberOfFriends = inputOfFriends(); | ||
| calc.input(numberOfFriends); | ||
| } | ||
|
|
||
|
|
||
|
|
||
| public static int inputOfFriends() { | ||
| Scanner scanner = new Scanner(System.in); | ||
| int numberOfFriends; | ||
| do { | ||
| System.out.println("Введите количество друзей: "); | ||
| while (!scanner.hasNextInt()){ | ||
| System.out.println("Вы ввели не целое число! Повторите ввод числа друзей:"); | ||
| scanner.next(); | ||
| } | ||
| numberOfFriends = scanner.nextInt(); | ||
| if (numberOfFriends <= 0) { | ||
| System.out.println("Число друзей не может быть равным нулю или быть отрицательным!"); | ||
| } else if (numberOfFriends == 1) { | ||
| System.out.println("Число друзей должно быть больше 1 !"); | ||
| } | ||
| } | ||
| while (numberOfFriends <= 1); | ||
| return numberOfFriends; | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| import java.util.Scanner; | ||
|
|
||
| public class calc { | ||
|
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 принято называть с большой буквы
Author
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. да, понял, что ошибся только перед pull request'ом :( |
||
| public static void input(int numberOfFriends) { | ||
| Scanner scanner = new Scanner(System.in); | ||
| String roubles; | ||
| String[] product = new String[100]; | ||
|
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. В данном случае ввод ограничен 100 товарами, после чего программа завершится. Скорее всего до 100 товаров не дойдет, но лучше подстраховаться и использовать ArrayList
Author
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. Хотелось выполнить работу соответственно уровню знаний, которые нам дали. Ну и, да, в реальности выполнения программы до 100 товаров никто не доберётся. Впрочем, как и в жизни :) Спасибо за ревью! |
||
| int numbersOfProduct = 0; | ||
| float sum = 0; | ||
| float price; | ||
|
|
||
| for (int i = 0; i < product.length; i++) { | ||
| System.out.println("Введите название блюда:"); | ||
| product[i] = scanner.next(); | ||
|
|
||
| do { | ||
| System.out.println("Введите его стоимость с копейками (в формате 0,00): "); | ||
| while (!scanner.hasNextFloat()) { | ||
| System.out.println("Вы ввели не число! Повторите ввод цены:"); | ||
| scanner.next(); | ||
| } | ||
| price = scanner.nextFloat(); | ||
| } while (price <= 0); | ||
|
|
||
| sum += price; | ||
| numbersOfProduct++; | ||
| System.out.println("Добавлено!\n Добавите ещё блюдо? Нет - введите Завершить. Да - введите любой символ"); | ||
| String answer = scanner.next(); | ||
| if (answer.equalsIgnoreCase("завершить")) { | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| printAllProducts(numbersOfProduct,product); | ||
|
|
||
| roubles = getRubleAddition((int) sum / numberOfFriends); | ||
|
|
||
| System.out.printf("\nС каждого друга по %.2f %s\n", sum / numberOfFriends, roubles); | ||
| } | ||
|
|
||
| private static void printAllProducts(int numbersOfProduct, String[] product){ | ||
| System.out.println("\n\"Добавленные товары:\" "); | ||
| for (int j = 0; j < numbersOfProduct; j++) { | ||
| if (product[j].isEmpty()) { | ||
| break; | ||
| } else { | ||
| System.out.println(product[j]); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public static String getRubleAddition(int number){ | ||
| float predPosCifra = number % 100 / 10; | ||
| if (predPosCifra == 1) | ||
| { | ||
| return "рублей"; | ||
| } | ||
| switch (number % 10) | ||
| { | ||
| case 1: | ||
| return "рубль"; | ||
| case 2: | ||
| case 3: | ||
| case 4: | ||
| return "рубля"; | ||
| default: | ||
| return "рублей"; | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Можно запустить программу одной строчкой
calc.input(inputOfFriends());There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Точно. Лишний код получился.