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

Проектная работа 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

Open
VirusDobra wants to merge 1 commit into main
base: main
Choose a base branch
Loading
from dev
Open
Show file tree
Hide file tree
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
39 changes: 39 additions & 0 deletions src/main/java/Calculator.java
View file Open in desktop
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 = "Завершить";
Copy link

@kirillNay kirillNay Jul 2, 2023

Choose a reason for hiding this comment

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

⏫ Обычно в нейминге переменных используются английские слова:

  • chek -> receipt
  • obshag -> common
  • many -> money

VirusDobra reacted with thumbs up emoji
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;

}

}



33 changes: 33 additions & 0 deletions src/main/java/Friends.java
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import java.util.Scanner;

public class Friends {

boolean restart = true;
Copy link

@kirillNay kirillNay Jul 2, 2023

Choose a reason for hiding this comment

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

⏫ Переменная restart используется только в методе friends, поэтому нам не обязательно создавать как поле класса. Мы можем объявить ее лишь в поле friends



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Введите сколько вас гостей: ");
Copy link

@kirillNay kirillNay Jul 2, 2023

Choose a reason for hiding this comment

The 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;
}
}

15 changes: 13 additions & 2 deletions src/main/java/Main.java
View file Open in desktop
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();







}

}
}

57 changes: 57 additions & 0 deletions src/main/java/Result.java
View file Open in desktop
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(){
Copy link

@kirillNay kirillNay Jul 2, 2023

Choose a reason for hiding this comment

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

⏫ Лучше стараться называть все функции с маленькой буквы, такой принцип нейминга общепринятый в java и kotlin

double zrachKa,peOple,reShala,celoe;
Copy link

@kirillNay kirillNay Jul 2, 2023

Choose a reason for hiding this comment

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

⏫ Также при нейминг переменных лучше придерживаться camelCase способа - каждое новое слово в названии пишется с большой буквы

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;
Copy link

@kirillNay kirillNay Jul 2, 2023

Choose a reason for hiding this comment

The 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("Рубля");
}

*/

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