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