-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathEveryday.java
More file actions
31 lines (26 loc) · 830 Bytes
/
Copy pathEveryday.java
File metadata and controls
31 lines (26 loc) · 830 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
record Money(BigDecimal amount) {
Money add(Money other) {
return new Money(amount.add(other.amount));
}
}
class Product {
private final String name;
private Money price;
Product(String name, Money price) {
this.name = name;
this.price = price;
}
String getName() { return name; }
Money getPrice() { return price; }
void setPrice(Money price) { this.price = price; }
}
void main() {
var lamp = new Product("Desk lamp", new Money(new BigDecimal("30")));
lamp.setPrice(lamp.getPrice().add(new Money(new BigDecimal("5"))));
IO.println(lamp.getName() + " costs " + lamp.getPrice().amount());
try {
IO.println(Files.readString(Path.of("orders.csv")));
} catch (IOException e) {
IO.println("Could not read " + e.getMessage());
}
}