This repository was archived by the owner on Mar 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBankTransaction.java
More file actions
73 lines (56 loc) · 1.5 KB
/
Copy pathBankTransaction.java
File metadata and controls
73 lines (56 loc) · 1.5 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/**
* Class for representing bank transactions.
* @author: Hunter M. Shaw
*/
public class BankTransaction implements Comparable<BankTransaction> {
private int sender, recipient;
private double amount;
public BankTransaction(int sender, int recipient, double amount) {
this.sender = sender;
this.recipient = recipient;
this.amount = amount;
}
public int getSender() {
return sender;
}
public void setSender(int sender) {
this.sender = sender;
}
public int getRecipient() {
return recipient;
}
public void setRecipient(int recipient) {
this.recipient = recipient;
}
public double getAmount() {
return amount;
}
public void setAmount(double amount) {
this.amount = amount;
}
@Override
public int compareTo(BankTransaction o) {
if(this.getAmount() == o.getAmount()) {
return 0;
} else if(this.getAmount() < o.getAmount()) {
return -1;
} else {
return 1;
}
}
//Takes in an object, Check to make sure it is an instance of Bank.
@Override
public boolean equals(Object o) {
if (!(this instanceof BankTransaction && o instanceof BankTransaction)) {
return false;
}
BankTransaction bt = (BankTransaction)o;
return (this.getAmount() == bt.getAmount() && this.getSender() == bt.getSender() && this.getRecipient() == bt.getRecipient());
}
@Override
public String toString() {
return "Sender: {"+this.sender+
"} Recipient: {"+this.recipient+
"} Amount: {"+this.amount+"}";
}
}