Java Enumeration Usage Examples

Source: Internet
Author: User

Package Com.sp.eclipse; Public classDemo3 {//Enumeration Usage Examples     Public Static voidMain (string[] args) {intGrade = -, Grade2 = the; String rString= Grade.getname (Grade);//incoming score, output score descriptionSystem. out. println ("Score:"+ Grade +"divided----"+rString); String rString2= Grade.getname (Grade2);//incoming score, output score descriptionSystem. out. println ("Score:"+ Grade2 +"divided----"+rString2); }    //enumeration method to define the fractional level description     Public enumGrade {A ("Excellent", -, -), B ("Good", the, the), C ("Pass", -, -), D ("inferior lattice",0, -); PrivateString name; Private intmin, Max; //Build Function        PrivateGrade (String name,intMinintmax) {             This. Name =name;  This. Min =min;  This. Max =Max; }                //Common Methods         Public StaticString GetName (intgrade) {String rString="" ;  for(Grade g:grade.values ()) {if(Grade >= g.getmin () && grade <=G.getmax ()) {rString= G.getname () +g.tostring (); }            }            returnrString; } @Override//overriding the ToString method         PublicString toString () {return "(Level:"+ getName () +"----Fractional interval:"+ getmin () +"~"+ Getmax () +")"; }                //The following are the field property read Settings         PublicString GetName () {returnname; }         Public voidsetName (String name) { This. Name =name; }         Public intgetmin () {returnmin; }         Public voidSetmin (intmin) {             This. Min =min; }         Public intGetmax () {returnMax; }         Public voidSetmax (intmax) {             This. Max =Max; }    }}

Java Enumeration Usage Examples

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.