forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGood.java
More file actions
24 lines (21 loc) · 876 Bytes
/
Good.java
File metadata and controls
24 lines (21 loc) · 876 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
public class Good {
public double price = 0.00;
public String name = "New Good";
public String goodCreated(String name, double price) { // Метод создания товара.
this.priceSet(price);
this.nameSet(name);
String formattedDouble = String.format("%.2f", this.price); // Можно было бы вынести в отдельный метод, чтобы было DRY, но не вижу смысла;
String goodCreated = this.name + formattedDouble;
return goodCreated;
}
public double priceSet(double price) {
this.price = price;
// System.out.println("Price has set " + this.price);
return this.price;
}
public String nameSet(String name) {
this.name = name;
// System.out.println("Name has set " + this.name);
return this.name;
}
}