-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMember.java
More file actions
60 lines (54 loc) · 1.71 KB
/
Member.java
File metadata and controls
60 lines (54 loc) · 1.71 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
/**
Write a description of class Member here.*
@author (your name)
@version (a version number or a date)
*/
public class Member extends Person
{
PaymentList paymentlist;
private Payment payment;
private int maxNoOfPayments = 12;
boolean paid;
Member(String name, String address, String phone)
{
this.name = name;
this.address = address;
this.phone = phone;
this.paymentlist = new PaymentList(maxNoOfPayments);
}
public boolean makePayment(Payment p)
{
// if not paid
if (!paid) {
// Ensure paymentlist is not null
if (paymentlist == null) {
paymentlist = new PaymentList(10); // You might need to adjust the size
}
paymentlist.add(p);
// Check if the number of payments has reached the maximum
if (paymentlist.getTotal() >= maxNoOfPayments) {
paid = true; // Set paid to true if the maximum number of payments is reached
}
return true; // Payment successful
} else {
System.out.println("This member has already paid in full.");
return false; // Payment unsuccessful
}
}
public PaymentList getPayment()
{
return paymentlist; // return paymentlist
}
public String toString()
{
String result = "";// loop through payments
for (int i = 0; i < paymentlist.getTotal(); i++) {
result = paymentlist.getPayment(i).toString() + "\n";
}
return " Name: " + name + "\n Phone: " + phone + "\n Address: " + address + " \nPayment Info: " + result;
}
public void print()
{
System.out.println(toString());
}
}