Repository navigation
Expand file tree
/
Copy pathTransaction.java
More file actions
139 lines (128 loc) · 3.13 KB
/
Copy pathTransaction.java
File metadata and controls
139 lines (128 loc) · 3.13 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import java.util.Date;
import java.text.SimpleDateFormat;
/**
* represents a transaction
*
*/
public class Transaction
{
// the transaction amount
private double amount;
// the transaction type
private String type;
// the transaction reference
private String reference;
// the transaction date
private Date date;
/**
* Constructor for objects of class Transaction
*/
public Transaction()
{
amount = 0;
type = "C";
reference = "default";
date = new Date();
}
/**
* Constructor for objects of class Transaction
*/
public Transaction(String reference)
{
amount = 0;
type = "C";
this.reference = reference;
date = new Date();
}
/**
* Constructor for objects of class Transaction
*
* @param amount the transaction amount
* @param type the transaction type
* @param reference the transaction reference
* @param date the transaction date
*/
public Transaction(double amount, String type, String reference, Date date)
{
this.amount = amount;
this.type = type;
this.reference = reference;
this.date = date;
}
/**
* returns the amount
*
* @return the transaction amount
*/
public double getAmount()
{
return amount;
}
/**
*
* @return the transaction type
*/
public String getType()
{
return type;
}
/**
* returns the transaction reference
*
* @return the transaction reference
*/
public String getReference()
{
return reference;
}
/**
* returns the transaction date
*
* @return the transaction date
*/
public Date getDate()
{
return date;
}
/**
* returns a string representation of the transaction date
*
* @return the date string
*/
public String getDateString()
{
SimpleDateFormat formatter = new SimpleDateFormat("EEE, MMM d, yyyy" );
String dateString = formatter.format(date);
return dateString;
}
/**
* returns a string representation of the transaction
*
* @return the string representation
*/
@Override
public String toString()
{
return String.format("Amount: %4.2f, Type: %s, Ref: %s,Date: %s",
amount, type, reference, this.getDateString());
}
/**
* Returns true if this object and the object under test have the
* same value in the description property.
* Modify this method if you want to define equality differently
*
* @param o the object to be tested for equality with this one
* @return true or false
*/
public boolean equals(Object o)
{
if (this == o) return true;
if (o == null) return false;
if (getClass() != o.getClass()) return false;
Transaction test = (Transaction) o;
if (this.reference.compareTo(test.reference) == 0)
return true;
else
return false;
}
}