Advertisement
mokahato

Citizen

Mar 25th, 2019
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.49 KB | None | 0 0
  1. /**
  2.  * COSC 1020 - Project 6
  3.  * 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.
  4.  * @author Chris Nadolny Conor Ward
  5.  * Instructor Jain
  6.  * TA-BOT:MAILTO  chris.nadolny@marquette.edu conor.ward@marquette.edu
  7.  */
  8. public class Citizen implements OrderedSet{
  9.     private String name;
  10.     protected Candidate candidate;
  11.    
  12.     public String getName(){
  13.         return name;
  14.     }
  15.    
  16.     public Citizen(String name) {
  17.         this.name = name;  
  18.     }
  19.    
  20.     public Candidate getCandidate() {
  21.         return this.candidate;
  22.     }
  23.     public OrderedSet[] sort(OrderedSet[] s, int criterion) {
  24.         OrderedSet temp;
  25.         if (s==null) return null;
  26.         if (criterion != 0) return s;
  27.         else {
  28.             for (int i = 0; i < s.length-1; i++) {
  29.                 for (int j = i+1; j < s.length; j++) {
  30.                     if (((Citizen) s[i]).getName().compareTo(((Citizen) s[j]).getName())>0) {
  31.                         temp = s[i];
  32.                         s[i] = s[j];
  33.                         s[j] = temp;
  34.                     }
  35.                 }
  36.             }
  37.             return s;
  38.         }
  39.     }
  40.     public void votesFor(Candidate candidate) {
  41.         this.candidate = candidate;
  42.         candidate.increaseSupporterBy(1);
  43.     }
  44.     public static void main(String[] args) {
  45.         Candidate can_1 = new Candidate("Bart",'X');
  46.         Candidate can_2 = new Candidate("Bob",'O');
  47.         Citizen cit_1 = new Citizen("john");
  48.         Citizen cit_2 = new Citizen("Tom");
  49.         cit_1.votesFor(can_1);
  50.         cit_2.votesFor(can_2);
  51.         System.out.println(can_2.getSupporters());
  52.         System.out.println(cit_1.getCandidate());
  53.         System.out.println(cit_2.getCandidate());
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement