-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRewardsCreditAccount.java
More file actions
52 lines (43 loc) · 1.97 KB
/
RewardsCreditAccount.java
File metadata and controls
52 lines (43 loc) · 1.97 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
// The assignment for this week is to implement the missing methods
// of two classes: CreditAccount and RewardsCreditAccount.
// DO NOT REMOVE THE private DESIGNATION OF ANY OF THE MEMBER VARIABLES!!!
public class RewardsCreditAccount extends CreditAccount {
private int points; //For every dollar spent (rounded down),
//the credit account gets a point
// For creating a new RewardsCreditAccount object, starting with points
public RewardsCreditAccount(String accountHolder, double balance,
double interestRate, int points) {
//this constructor should initialize all of the variables
//with the given values. Don't change the names of the parameters!
super(accountHolder, balance, interestRate);
this.points = points;
}
// For creating a new RewardsCreditAccount object, starting with 0 points
public RewardsCreditAccount(String accountHolder, double balance,
double interestRate) {
//this constructor should initialize points to zero
//(in addition to initializing the other variables)
// This can be (and should be) accomplished in one line of code!
this(accountHolder, balance, interestRate, 0);
}
public void makeCharge(double amount) {
//this method should increase the balance and
//also award the correct amount of points
super.makeCharge(amount);
points += (int) amount;
}
public String toString() {
//This method should return a String like the toString method
//in CreditAccount, but with an added
//comma and a space before appending the points
//For example, an account with "Joe F. Pyne" as the accountHolder,
//7384.28 as the balance, 0.173 as the interest rate,
// and 567 points should return the String
// "Joe F. Pyne, $7384.28, 17.3%, 567 points"
// Make this method as short and succinct as possible!
return String.format("%s, %d points", super.toString(), points);
}
public int getPoints() {
return points;
}
}