Repository navigation
перый пулл #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
chromasoma
wants to merge
14
commits into
main
Choose a base branch
from
dev
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
перый пулл #1
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
ac87206
1-2 почти
chromasoma eb32e2d
почти
chromasoma 6da219f
обработтаь искл-я надо
chromasoma 4dc5a5b
Добавила 2 класса
chromasoma 22a55db
критические ошибки
chromasoma ba50f45
\ 4 два раза неправильный ввод - исправить
chromasoma 131c4f3
Исправлен ввод
chromasoma 7120b2c
Исправлен ввод
chromasoma b197cc2
-можно создать товар без названия и с ценой 0
chromasoma 8a2de0e
убрала комменты
chromasoma 908c5c5
Убрала лишний континью
chromasoma ccf55b2
Убрала лишний континью
chromasoma 3b8c127
String.format
chromasoma 7c7beb4
String.format
chromasoma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| import java.util.ArrayList; | ||
| import java.util.Scanner; | ||
|
|
||
| public class Calculator { | ||
|
|
||
| private double sum = 0; | ||
| private int number; | ||
|
|
||
| ArrayList<Product> goods = new ArrayList<>(); | ||
| public void setNumber() | ||
| { | ||
| Scanner scanner = new Scanner(System.in); | ||
| String temp; | ||
| System.out.println("На скольких человек необходимо разделить счёт?"); | ||
| while (true) { | ||
| try | ||
| { | ||
| temp = scanner.nextLine().trim(); | ||
| number = Integer.parseInt(temp); | ||
| if (number <= 1 || !temp.matches("^[0-9]+$")) | ||
| { | ||
| throw new Exception("Неверное значение! Попробуйте еще раз."); | ||
| } | ||
| break; | ||
| } | ||
| catch (Exception e) | ||
| { | ||
| System.out.println("Неверное значение! Попробуйте еще раз."); | ||
| continue; | ||
| } | ||
| } | ||
| } | ||
| public void setProducts() | ||
| { | ||
| Scanner scanner = new Scanner(System.in); | ||
|
|
||
| while (true) { | ||
| //1) Запросите у пользователя название товара и его стоимость. Стоимость должна быть в | ||
| // формате рубли.копейки, например 10.45 или 11.40. | ||
|
|
||
| Product product = new Product(); | ||
| product.setProduct(); | ||
| sum += product.getPrice(); | ||
| goods.add(product); | ||
|
|
||
| System.out.println("Хотите ли Вы добавить еще один товар?"); | ||
| String answer = scanner.nextLine(); | ||
| if (answer.equalsIgnoreCase("завершить")) | ||
| { | ||
| this.printAll(); | ||
| break; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public void printAll() | ||
| { | ||
| Formatter f = new Formatter(); | ||
|
|
||
| System.out.println("Добавленные товары:"); | ||
| for (Product g: goods) | ||
| { | ||
| int r = (int)(g.getPrice() - (g.getPrice() % 1)); | ||
| String rr = f.getRubles(r); | ||
|
|
||
| System.out.println(g.getName() + " " + g.getPrice() + rr); | ||
| } | ||
| System.out.println("Каждый человек должен заплатить " + | ||
| String.format("%.2f", sum / number) + f.getRubles((int)(sum / number)) + "."); | ||
| } | ||
|
|
||
| public void addProduct(Product p) | ||
| { | ||
| goods.add(p); | ||
| sum += p.getPrice(); | ||
| } | ||
| public boolean deleteProduct(Product p) { return goods.remove(p); } | ||
| public double getSum() { return sum; } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import java.util.ArrayList; | ||
|
|
||
| public class Formatter | ||
| { | ||
| public String getRubles(int r) | ||
| { | ||
| if ((r % 10) == 1) | ||
| return " рубль "; | ||
| else if ((r % 10)>=2 && (r % 10)<=4) | ||
| return " рубля "; | ||
| else | ||
| return " рублей "; | ||
| } | ||
| public String[] getRublesAndKopecks(double price) | ||
| { | ||
| int rInNum; String rInWords; | ||
| int kInNum; String kInWOrds; | ||
| String partOne; | ||
| String partTwo; | ||
|
|
||
| String[] parsesParts = String.valueOf(price).split("\\."); | ||
| rInNum = Integer.parseInt(parsesParts[0]); | ||
| if (!parsesParts[1].substring(0,1).equals("0")) | ||
| { | ||
| kInNum = Integer.parseInt(parsesParts[1])*10; | ||
| } | ||
| else | ||
| { | ||
| kInNum = Integer.parseInt(parsesParts[1]); | ||
| } | ||
|
|
||
| if ((rInNum % 10) == 1) | ||
| rInWords = " рубль "; | ||
| else if ((rInNum % 10)>=2 && (rInNum % 10)<=4) | ||
| rInWords = " рубля "; | ||
| else | ||
| rInWords = " рублей "; | ||
|
|
||
| if ((kInNum % 10) == 1) | ||
| kInWOrds = " копейка "; | ||
| else if ((kInNum % 10)>=2 && kInNum % 10 <=4) | ||
| kInWOrds = " копейки "; | ||
| else | ||
| kInWOrds = " копеек "; | ||
|
|
||
| String[] res = {Integer.toString(rInNum), rInWords, Integer.toString(kInNum), kInWOrds}; | ||
| return res; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,12 @@ | ||
| import java.util.Enumeration; | ||
| import java.util.Scanner; | ||
|
|
||
| public class Main { | ||
| public static void main(String[] args) { | ||
| System.out.println("Hello world!"); | ||
| Calculator goodsCalc = new Calculator(); | ||
| //количество человек | ||
| goodsCalc.setNumber(); | ||
| //добавление товаров | ||
| goodsCalc.setProducts(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| import java.util.ArrayList; | ||
| import java.util.Scanner; | ||
|
|
||
| public class Product { | ||
| private String name; | ||
| private double price; | ||
| public void setProduct() | ||
| { | ||
| Scanner scanner = new Scanner(System.in); | ||
|
|
||
| while(true) { | ||
| System.out.println("Введите название товара:"); | ||
| name = scanner.nextLine().trim(); // исправлено | ||
| if (name == null || name.isEmpty()) | ||
| { | ||
| System.out.println("Неверное значение! Попробуйте еще раз."); | ||
| } | ||
| else { | ||
| break; | ||
| } | ||
| } | ||
| System.out.println("Введите стоимость товара:"); | ||
| String temp; | ||
| while(true) | ||
| { | ||
| try | ||
| { | ||
| temp = scanner.nextLine().trim(); | ||
| price = Double.parseDouble(temp); | ||
| if (price <= 0) { | ||
| throw new Exception("Некорректные данные!"); | ||
| } | ||
| Formatter f = new Formatter(); | ||
| String[] s = new String[4]; | ||
| s = f.getRublesAndKopecks(price); | ||
|
|
||
| System.out.println(String.format("Товар %s с ценой %s %s %s %s успешно добавлен!", name, s[0], s[1], s[2], s[3])); | ||
| break; | ||
| } | ||
| catch (Exception e) | ||
| { | ||
| System.out.println("Неверное значение! Попробуйте еще раз."); | ||
| } | ||
|
|
||
| } | ||
| } | ||
|
|
||
| public void setName(String n) | ||
| { | ||
| name = n; | ||
| } | ||
| public void setPrice(double c) | ||
| { | ||
| price = c; | ||
| } | ||
| public String getName() | ||
| { | ||
| return name; | ||
| } | ||
| public double getPrice() | ||
| { | ||
| return price; | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
можно вместо trim() + isEmpty использовать isBlank()
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.
круто, спасибо! но убрать в данном случае пробелы - хорошо) а так буду иметь в виду.