forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProductItem.java
More file actions
59 lines (39 loc) · 1.46 KB
/
ProductItem.java
File metadata and controls
59 lines (39 loc) · 1.46 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import java.util.Scanner;
public class ProductItem {
public String name;
public double price;
public void askProductData(){
Scanner scanner = new Scanner(System.in);
while (true){
System.out.println("Введите название товара:");
name = scanner.nextLine();
if(!name.trim().equals("")){
break;
}
System.out.println("Ошибка! Название не должно быть пустой строкой");
}
while(true) {
System.out.println("Введите стоимость товара:");
try {
price = scanner.nextDouble();
if(!scanner.nextLine().trim().equals("")){
System.out.println("Введите только число в формате 0.00 без дополнительных знаков");
continue;
}
if (price > 0) {
break;
}
} catch (Exception e) {
if(scanner.hasNextLine()) scanner.nextLine();
//scanner = new Scanner(System.in);
}
System.out.println("Введите число в формате 0.00");
}
}
public String getNameAndPrice(){
return name + " " + AddFormat.rub(price);
}
public String getPrice(){
return AddFormat.rub(price);
}
}