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
34 lines (29 loc) · 882 Bytes
/
Product.java
File metadata and controls
34 lines (29 loc) · 882 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
32
33
34
import java.util.Locale;
import java.util.Scanner;
public class Product {
public String name;
public double price;
private Scanner scanner;
public Product create() {
scanner = new Scanner(System.in);
addName();
addPrice();
return this;
}
public void addName() {
System.out.println("Введите название продукта:");
name = scanner.nextLine();
}
public void addPrice() {
String priceAsString;
do {
System.out.println("Введите цену продукта:");
priceAsString = scanner.nextLine();
this.price = Validator.validateProductPrice(priceAsString);
}
while (this.price == -1);
}
public String toString() {
return String.format(Locale.ENGLISH, "%s %.2f руб.", name, price);
}
}