단순 투표 애플릿

1905 단어 활용단어참조
프로그램 결과:
Tom:      !
Tom         !
Bob:      !
Jack:      !
----------------------------------
      : 3
         :
----------------------------------
Jack
Bob
Tom
----------------------------------
package apq.Vote;
import java.util.*;
public class Voter {
	private static final int MAX_COUNT = 100;	//     ,         
	private static int count = 0;	//   
	private static Set<Voter> voters = new HashSet<Voter>();	//          
	private String name;	//    ,     
	
	public Voter(String name) { this.name = name; }
	
	/**  */
	public void voteFor() {
		if(count == MAX_COUNT) {
			p("       !"); return;
		}
		if(voters.contains(this)) {
			p(name + "         !");
		}
		else {
			count++;
			voters.add(this);
			p(name + ":      !");
		}
	}
	
	/**      */
	public static void printVoteResult() {
		p("----------------------------------");
		p("      : " + count);
		p("         :");
		p("----------------------------------");
		for(Voter v : voters) {
			p(v.name);
		}
		p("----------------------------------");
	}
	
	/**  */
	public static void p(Object o) {
		System.out.println(o);
	}
//---------------------------------------------
// Main Method
	public static void main(String[] args) {
		Voter tom = new Voter("Tom");
		Voter bob = new Voter("Bob");
		Voter jack = new Voter("Jack");
		
		tom.voteFor(); tom.voteFor();
		bob.voteFor();
		jack.voteFor();
		
		Voter.printVoteResult();
	}

}

좋은 웹페이지 즐겨찾기