forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddProduct.java
More file actions
32 lines (27 loc) · 1.03 KB
/
AddProduct.java
File metadata and controls
32 lines (27 loc) · 1.03 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
import java.util.Scanner;
public class AddProduct {
String product;
float price;
public void addproduct() {
Scanner scanner = new Scanner(System.in);
System.out.println("Введите название товара");
this.product = scanner.next();
while (true) {
System.out.println("Введите цену товара");
scanner = new Scanner(System.in);
if (scanner.hasNextFloat()) {
this.price = scanner.nextFloat();
if (this.price > 0) {
System.out.println("Товар успешно добавлен");
break;
} else {
System.out.println("Введите число больше 0");
scanner = new Scanner(System.in);
}
} else {
System.out.println("Введите положительное число");
scanner = new Scanner(System.in);
}
}
}
}