-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCampaign.java
84 lines (72 loc) · 1.8 KB
/
Campaign.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
import java.util.ArrayList;
/**Class to hold campaign information for a political campaign.
*
* @author logan
* @version 1.0
*/
public class Campaign {
//data variables
private String candidateName;
private ArrayList<Donor> donors = new ArrayList<Donor>();
//constructors
public Campaign(String name) {
candidateName = name;
}
//methods
public String getCandidateName() {
return candidateName;
}
public String getDonors() {
String result = candidateName + "\n";
result += donors.toString();
return result;
}
public double getAllDonations() {
double total = 0;
for(int i = 0; i < donors.size(); i++) {
total += donors.get(i).getTotalDonations();
}
return total;
}
public void addDonor(String name) {
Donor newDonor = new Donor(name);
donors.add(newDonor);
}
//This method searches for the donor in the donors list
//If the donor is found, returns the donation amount, if not, returns -1
public double getDonation(String donor) {
for(int i = 0; i < donors.size(); i++) {
Donor currentDonor = donors.get(i);
if(currentDonor.getName().equals(donor)) {
return currentDonor.getTotalDonations();
}
}
return -1;
}
public String getDonationList(String donor)
{
for (int i=0; i<donors.size(); ++i)
{
Donor d = donors.get(i);
if (d.getName().equals(donor))
{
return d.toString();
}
}
return "No donor with that name was found";
}
public void addDonation(String donorName, double donation) {
boolean donorFound = false;
for(int i = 0; i < donors.size(); i++) {
Donor currentDonor = donors.get(i);
if(currentDonor.getName().equals(donorName)) {
donorFound = true;
currentDonor.addDonation(donation);
}
}
if(!donorFound) {
Donor newDonor = new Donor(donorName, donation);
donors.add(newDonor);
}
}
}