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
38 lines (29 loc) · 1.02 KB
/
Product.java
File metadata and controls
38 lines (29 loc) · 1.02 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
import java.util.Scanner;
public class Product {
final private String title;
final private double price;
Scanner scanner = new Scanner(System.in);
Product() {
title = findTitle();
price = findPrice();
}
private String findTitle() {
System.out.println("Введите название товара: ");
return scanner.nextLine();
}
private double findPrice() {
System.out.println("Введите его стоимость в формате \"рубли.копейки\": ");
do {
String tmpStr = scanner.nextLine().trim();
if (tmpStr.matches("^[0-9]+\\.[0-9]{2}?$"))
return Double.parseDouble(tmpStr);
System.out.println("Неверный ввод. Пожалуйста, введите стоимость в формате \"рубли.копейки\": ");
} while (true);
}
String getProductName() {
return title;
}
double getProductPrice() {
return price;
}
}