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

Comments

Реквест по заданию в спринте 2 Практикума#1

Open
sred75 wants to merge 9 commits intomain from
master
Open

Реквест по заданию в спринте 2 Практикума #1
sred75 wants to merge 9 commits intomain from
master

Conversation

@sred75
Copy link
Owner

@sred75 sred75 commented Oct 31, 2022

Рабочий коммит - 050

s-buvaka and others added 9 commits July 27, 2022 23:03
# Conflicts:
#	src/main/java/goodsAddingEngine.java
...le, переписал логику в новом классе goodsEntering, вылетов нет
import java.util.Scanner;
public class goodsEntering {
public static int goodsArrayCreating(){
int qtyOfGoods= 0;
Copy link

@MagicUnderHood MagicUnderHood Nov 1, 2022

Choose a reason for hiding this comment

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

Можешь применить в студии автоформатирование (в выбранном файле, сверху вкладка Code - Reformat Code, либо Ctrl+Alt+L), тогда автоматически код выправится.

sred75 reacted with thumbs up emoji

System.out.println(calculator.cart);
System.out.println("Каждому человеку к оплате: " + formatter.roundResult(result) + " " + formatter.formatValue(result));
double payment = (double) sum / qtyOfGuys;
Copy link

@MagicUnderHood MagicUnderHood Nov 1, 2022

Choose a reason for hiding this comment

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

Приведение типа к double (код (double) перед sum) необязательно, потому что sum и так типа double

sred75 reacted with thumbs up emoji
public static int goodsArrayCreating(){
int qtyOfGoods= 0;
String enteredName = "";
Double enteredPrice = 0d;
Copy link

@MagicUnderHood MagicUnderHood Nov 1, 2022

Choose a reason for hiding this comment

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

Double с большой буквы это класс-обертка, а здесь достаточно использовать примитив double. Подробнее про классы-обертки будет в спринте 3, тема 1, урок 2 Списки. ArrayList
Инициализация 0d здесь необязательно, поскольку до использования переменной её значение будет перезаписано enteredPrice = price.nextDouble();

sred75 reacted with thumbs up emoji
Copy link
Owner Author

Choose a reason for hiding this comment

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

Очень долго промучился с проверками и типами данных(( В результате душевной травмы пробовал принудительно присваивать типы некоторым значениям переменных))
Стало большим сюрпризом, что нужно очищать буфер сканера, иначе случался вылет в ошибку...

MagicUnderHood reacted with thumbs up emoji
Double enteredPrice = 0d;
Scanner name = new Scanner(System.in);
Scanner price = new Scanner(System.in);
while (!enteredName.equalsIgnoreCase("Завершить")) {
Copy link

@MagicUnderHood MagicUnderHood Nov 1, 2022

Choose a reason for hiding this comment

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

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

sred75 reacted with eyes emoji
Copy link
Owner Author

Choose a reason for hiding this comment

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

Сэкономил строчки кода на проверках и break)) Спасибо, что обратили внимание 👍

MagicUnderHood reacted with laugh emoji
qtyOfGoods = goodsEntering.goodsArrayCreating();

System.out.println("\nДОБАВЛЕННЫЕ ТОВАРЫ: ");
while (i < qtyOfGoods){
Copy link

@MagicUnderHood MagicUnderHood Nov 1, 2022

Choose a reason for hiding this comment

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

Можно вместо qtyOfGoods использовать goodsArray.size(). Это ещё и предотвратит от попытки получить элемент по индексу, который больше размера массива

sred75 reacted with thumbs up emoji
@@ -0,0 +1,34 @@
import java.util.Scanner;
public class goodsEntering {
public static int goodsArrayCreating(){
Copy link

@MagicUnderHood MagicUnderHood Nov 1, 2022

Choose a reason for hiding this comment

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

Можно метод делать не статическим, тогда для его вызова надо создавать экземпляр класса goodsEntering, и вызывать метод от экземпляра

sred75 reacted with eyes emoji
import java.util.Scanner;
public class howManyGuys {
static int qtyOfGuys;
public static void main(String[] args) {
Copy link

@MagicUnderHood MagicUnderHood Nov 1, 2022

Choose a reason for hiding this comment

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

Этот метод здесь лучше убрать, потому что точка входа в приложение в методе main класса Main

sred75 reacted with thumbs up emoji
public static int howManyGuys() {
boolean flag = false;
System.out.print("На какое кол-во человек разделить счёт? ");
while (!flag) {
Copy link

@MagicUnderHood MagicUnderHood Nov 1, 2022

Choose a reason for hiding this comment

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

Достаточно здесь написать в скобках true, и необходимости в переменной flag не будет

sred75 reacted with thumbs up emoji
String payOutput;
int payInputNorm = (int) payInput;
String payString = Integer.toString(payInputNorm);
char endOfPayment = payString.charAt(payString.length() - 1);
Copy link

@MagicUnderHood MagicUnderHood Nov 1, 2022

Choose a reason for hiding this comment

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

Можно более простые варианты: для определения последней цифры - payInputNorm % 10. Плюс учесть, что для чисел 11-19 окончание слова - "рублей", поможет payInputNorm % 100

sred75 reacted with eyes emoji
Copy link
Owner Author

Choose a reason for hiding this comment

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

Классный подход, спасибо 👍)

MagicUnderHood reacted with laugh emoji
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

1 more reviewer

@MagicUnderHood MagicUnderHood MagicUnderHood left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

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