-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPromissoryNote.java
49 lines (39 loc) · 1.21 KB
/
PromissoryNote.java
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import java.util.HashMap;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author kdost
*/
public class PromissoryNote {
private HashMap<String, Double> note;
public PromissoryNote() {
this.note = new HashMap<String, Double>();
}
public void setLoan(String toWhom, double value) {
if (!this.note.containsValue(value)) {
this.note.put(toWhom, value);
} else {
System.out.println("This person already owes!!!");
}
}
public double howMuchIsTheDebt(String whose) {
if (this.note.containsKey(whose)) {
return this.note.get(whose);
}
return 0;
}
}
public class Main {
public static void main(String[] args) {
// Test your program here
PromissoryNote mattisNote = new PromissoryNote();
mattisNote.setLoan("Arto", 51.5);
mattisNote.setLoan("Mikael", 30);
System.out.println(mattisNote.howMuchIsTheDebt("Arto"));
System.out.println(mattisNote.howMuchIsTheDebt("Joel"));
}
}