-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCredit.java
134 lines (120 loc) · 2.9 KB
/
Credit.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
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
import java.io.IOException;
/**
* @author Ricardo Pena and Aaron Alarcon
* PinkBlink
* November 26, 2019
* CS3331
* Daniel Mejia
* Programming Assignment 5
*
* The template for this class is from Ricardo Pena, except as noted for each method
*
* Create a customer which has checking/savings/credit accounts and simulate various transactions.
*
* I confirm that the work of this assignment is completely my own.By turning in this assignment,
* I declare that I did not receive unauthorized assistance. Moreover, all the deliverables
* including, but not limited to the source code, lab report and output files were written and
* produced by me alone.
*/
public class Credit extends Account {
private static int numberOfAccounts = 3000;
final private static String type = "Credit";
private double limit;
/**
* Constructor
* @param acctNo Account Number
* @param balance Balance of account
*/
public Credit(String acctNo, String balance) {
super(acctNo, balance);
limit = Integer.MAX_VALUE;
numberOfAccounts++;
}
/**
* Constructor
* @param acctNo Account Number
* @param balance Balance of account
* @param limit Limit of account
*/
public Credit(String acctNo, String balance, double limit) {
super(acctNo, balance);
this.limit = limit;
numberOfAccounts++;
}
/**
* Constructor
* @param acctNo Account Number
* @param balance Balance of account
*/
public Credit(int acctNo, double balance) {
super(acctNo, balance);
}
/**
* Constructor
* @param acctNo Account Number
* @param balance Balance of account
* @param limit Limit of account
*/
public Credit(int acctNo, double balance, double limit) {
super(acctNo, balance);
this.limit = limit;
}
/**
* Constructor
* @param balance Balance of account
*/
public Credit(double balance) {
super(numberOfAccounts, balance);
numberOfAccounts++;
}
/**
* Creates a deep copy of the class object
* @return Returns deep copy of class object
*/
public Credit deepCopy() {
return new Credit(acctNo, balance, limit);
}
/**
* Setter
* @param limit Limit of account
*/
public void setLimit(double limit) {
this.limit = limit;
}
/**
* Getter
* @return limit
*/
public double getLimit() {
return limit;
}
/**
* Getter
* @return type
*/
public String getType() {
return type;
}
@Override
public boolean deposit(double amount) {
// TODO Auto-generated method stub
if(amount > Math.abs(balance)) {
System.out.println("Remaining balance is " + balance + ". Cannot pay more than remaining balance.");
return false;
}
else {
return super.deposit(amount);
}
}
@Override
public boolean withdraw(double amount) {
// TODO Auto-generated method stub
if(Math.abs(balance - amount) > Math.abs(limit)) {
System.out.println("Credit Limit of "+ this.limit +" has been reached.");
return false;
}
else {
return super.withdraw(amount);
}
}
}