forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProduct.java
More file actions
31 lines (24 loc) · 819 Bytes
/
Product.java
File metadata and controls
31 lines (24 loc) · 819 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
public class Product {
String name;
float price;
Product(String productName, float productPrice) {
name = productName;
price = productPrice;
}
static Product read() {
String name = TerminalReader.readString("Введите название товара:");
float price;
while (true) {
price = TerminalReader.readFloat("Введите цену товара:");
if (price >= 0) {
break;
}
System.out.println("Цена не должна быть отрицательным числом!");
}
return new Product(name, price);
}
@Override
public String toString() {
return String.format("– %s: %s", name, PriceFormatter.getHumanizedPrice(price));
}
}