Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * COSC 1020 - Project 6
- * This class takes a String name and uses it to create a citizen object, it then uses a sort method to order an array of Citizens.
- * @author Chris Nadolny Conor Ward
- * Instructor Jain
- * TA-BOT:MAILTO chris.nadolny@marquette.edu conor.ward@marquette.edu
- */
- public class Citizen implements OrderedSet{
- private String name;
- protected Candidate candidate;
- public String getName(){
- return name;
- }
- public Citizen(String name) {
- this.name = name;
- }
- public Candidate getCandidate() {
- return this.candidate;
- }
- public OrderedSet[] sort(OrderedSet[] s, int criterion) {
- OrderedSet temp;
- if (s==null) return null;
- if (criterion != 0) return s;
- else {
- for (int i = 0; i < s.length-1; i++) {
- for (int j = i+1; j < s.length; j++) {
- if (((Citizen) s[i]).getName().compareTo(((Citizen) s[j]).getName())>0) {
- temp = s[i];
- s[i] = s[j];
- s[j] = temp;
- }
- }
- }
- return s;
- }
- }
- public void votesFor(Candidate candidate) {
- this.candidate = candidate;
- candidate.increaseSupporterBy(1);
- }
- public static void main(String[] args) {
- Candidate can_1 = new Candidate("Bart",'X');
- Candidate can_2 = new Candidate("Bob",'O');
- Citizen cit_1 = new Citizen("john");
- Citizen cit_2 = new Citizen("Tom");
- cit_1.votesFor(can_1);
- cit_2.votesFor(can_2);
- System.out.println(can_2.getSupporters());
- System.out.println(cit_1.getCandidate());
- System.out.println(cit_2.getCandidate());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement