Skip to content

1st java module - #127

Closed
AndroidAndrey wants to merge 6 commits into
Yandex-Practicum:masterfrom
AndroidAndrey:master
Closed

AndroidAndrey wants to merge 6 commits into
Yandex-Practicum:masterfrom
AndroidAndrey:master

Conversation

@AndroidAndrey

Copy link
Copy Markdown

No description provided.

@AndroidAndrey

Copy link
Copy Markdown
Author

Надеюсь все сделал правильно, извините, что так вышло, у меня с Android Studio напряженные отношения

@MagicUnderHood

Copy link
Copy Markdown

Если у тебя есть сложности со студией, ты всегда можешь задать вопросы наставнику или наставнице, у них отношения со студией более длительные)

# Conflicts:
#	.idea/gradle.xml
#	src/main/java/Calc.java
# Conflicts:
#	.idea/gradle.xml
#	src/main/java/Calc.java
@AndroidAndrey

Copy link
Copy Markdown
Author

Сделал фичу с рублями, смотреть последний комит rubles #b66f80e

Comment thread src/main/java/Calc.java
System.out.println("Введите название товара");
String res = scanner.next();
// устанавливаем слово для остановки цикла
if (res.toUpperCase(Locale.ROOT).equals("ЗАВЕРШИТЬ")) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Или можно использовать equalsIgnoreCase()

Comment thread src/main/java/Calc.java
boolean cont = true;
//создаем бесконечный цикл вызова товара
while (cont) {
System.out.println("Введите название товара");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Можно дописать "Введите Завершить, чтобы закончить ввод", иначе пользователь не поймёт, что следует ввести для выхода

Comment thread src/main/java/Calc.java

public static void Calculator() {
Scanner scanner = new Scanner(System.in);
String result = "";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Студия подсказывает, что, хотя переменная инициализируется, она не используется после этого

Comment thread src/main/java/Calc.java
Scanner scanner = new Scanner(System.in);
String result = "";
double count = 0;
boolean cont = true;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Можно избавиться от переменной, если писать while(true), а в месте, где нужно выйти из цикла - писать break;

Comment thread src/main/java/Calc.java
System.out.println("Введите стоимость в формате: \'рубли.копейки' ");
String temp = scanner.next();
// проверка на то чтобы пользователь вводил только int стоимость
if (!checkPrice(temp)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Можно использовать scanner.hasNextFloat()

Comment thread src/main/java/Calc.java
System.out.println("Некорректные данные");
} else {
System.out.println("Товар " + res + " успешно добавлен");
count += Double.parseDouble(temp);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Можно использовать scanner.nextFloat()

Comment thread src/main/java/Calc.java
import java.util.Scanner;
public class Calc {

public static void Calculator() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Можно код ниже выполнять в отдельном методе, назвать его так, чтобы он отражал работу внутри, например, inputGoods, и вызывать этот метод в Main

Comment thread src/main/java/Users.java
System.out.println("Колличество пользователей = " + users);
break;
}
if(users<=1){

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Можно поставить else к предыдущему if вместо этого кода

Comment thread src/main/java/Calc.java

}
public static String rubles(double a) {
int rub = (int) Math.floor(a);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Отлично, что используешь переменную, всё сделано правильно

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants