-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPeople.java
More file actions
33 lines (29 loc) · 804 Bytes
/
Copy pathPeople.java
File metadata and controls
33 lines (29 loc) · 804 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
class People {
private String name;
private Map<People, Map<String, Double>> amountIOwe;
public People(String name){
this.name = name;
}
public addAmountOwed(People p, String currency, double amount) {
if(amountIOwe.get(p) == null){
amountIOwe.put(p, new HashMap<>());
}
if(amountIOwe.get(p).get(currency) == null){
amountIOwe.get(p).put(currency, 0);
}
int currentOwed = amountIOwe.get(p).get(currency);
amountIOwe.get(p).put(currency, currentOwed + amount);
}
public printOwed(){
for(People p: amountIOwe.getKeys()){
System.out.print(f"{name} owes {p.getName()} ");
for(String currency: amountIOwe.get(p).getKeys()){
System.out.print(f"{currency} {amountIOwe.get(p).get(currency)} ")
}
System.out.println();
}
}
public getName(){
return name;
}
}