统计选票的小程序,各位大侠帮个忙,谢谢
ray34 2007-11-14 11:55:49 要求:创建两个类Vote和Candidate.Vote类包含统计选票的数据域count,以及读取和处理选票的getCount,setCount,clear,increment和decrement方法,如下图:
Vote Candidate
count:int name: String
vote: Vote
+Count() numberOfCandidates: int
+getCount():int
+setCount(count: int): void +Candidate()
+clear(): void +Candidate(name: String, vote: Vote)
+increment(): void +getName(): String
+decrement(): void +getVote(): Vote
+getNumberOfCandidates(): int
clear方法将票数count置为0,increment和decrement方法增加和减少票数。Candidate类具有数据域name (代表的姓名),vote(记录代表接收的选票)和getname,getVote和getNumberOfCandidate方法,编写测试程序,统计竞选学生会主席的两个代表的选票。选票从键盘输入,数字1是代表1的选票,数字2是代表2的选票,数字-1扣除代表1的1张选票,-2扣除代表2的1张选票,数字0表示统计结束。