Static keyword Synthesis small application

Source: Internet
Author: User

 PackageUNIT4;Importcom.sun.java_cup.internal.version; Public classVoter {Private Static intMax_count =100; Private Static intcount; Private StaticVoter[] Voters=NewVoter[max_count]; PrivateString name;  PublicVoter (String name) { This. name=name; }     PublicString GetName () {returnname; }     Public voidvotefor () {if(count==max_count) {System.out.println ("Voting is over"); return ; }        if(Isexisted ( This) {System.out.println ("No duplicate votes allowed!"); }Else{Votersadd ( This); System.out.println ("Thank you for voting."); }    }     Public Static Booleanisexisted (Voter obj) { for(inti=0;i<count;i++){            if(Voters[i].getname () = =Obj.getname ()) {                return true; }        }        return false; }     Public Static voidvotersadd (Voter obj) {voters[count++]=obj; }     Public Static voidPrintvoteresult () {System.out.println ("The current number of votes is:" +count); System.out.println ("Voting voters are as follows:");  for(inti=0;i<count;i++) {System.out.println (Voters[i].getname ()); }    }     Public Static  voidMain (string[] args) {Voter Majun=NewVoter ("Ma June")); Voter Fly=NewVoter ("flying"); Voter Mike=NewVoter ("Mike"); Voter Majian=NewVoter ("Ma Jian");        Majun.votefor ();        Fly.votefor ();        Mike.votefor ();        Mike.votefor ();        Majian.votefor ();    Voter.printvoteresult (); }    }

Output Result:

Thank you for voting Thank you vote Thank you vote not allowed to repeat the vote ! Thank you for voting. The current number of votes is:4 The voters voted as follows: Ma June fly Mike Ma Jian

Static keyword Synthesis small application

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.