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
35 lines (30 loc) · 902 Bytes
/
Product.java
File metadata and controls
35 lines (30 loc) · 902 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
35
import java.util.Locale;
public class Product {
private String name;
private double price;
public Product(String name, double price) {
this.name = name;
this.price = price;
}
@Override
public String toString() {
return name + " - " + String.format(Locale.US,"%.2f", price) + sklonenie(price);
}
public static String sklonenie(double amount) {
int rubles = (int) amount;
int lastDigit = rubles % 10;
int lastTwoDigits = rubles % 100;
if (lastTwoDigits >= 11 && lastTwoDigits <= 19) {
return " рублей";
} else if (lastDigit == 1) {
return " рубль";
} else if (lastDigit >= 2 && lastDigit <= 4) {
return " рубля";
} else {
return " рублей";
}
}
public double getPrice() {
return price;
}
}