java中enum----枚举的学习(更新中)
1 package com.hdmaxfun; 2 3 import java.util.Scanner; 4 import com.icpc.Icpm; 5 import java.util.HashMap; 6 import java.util.Map;public class hdmaxfun{public static void main(String[] args){ 7 Icpm A = Icpm.D.getIcpmPlaceByCode("8"); 8 A.SetPlace("杭州"); 9 A=A.getIcpmPlaceByCode("2"); 10 //System.out.println(A.GetCode()+A.GetPlace()); 11 A=A.getIcpmPlaceByCode("8"); 12 //System.out.println(A.GetCode()+A.GetPlace()); 13 Icpm B = Icpm.G.getIcpmPlaceByCode("8"); 14 //System.out.println(B.GetCode()+B.GetPlace()); 15 for(Icpm itor : B.values()){ 16 System.out.println(itor.GetCode()+" "+itor.GetPlace()); 17 } 18 Map<String ,String >AMp = B.getResponse(); 19 System.out.println(AMp.get("respPlace")); 20 } 21 }
1 package com.icpc; 2 import java.util.HashMap; 3 import java.util.Map; 4 /*** 5 * 6 * @author hdmaxfun 7 * 8 */ 9 public enum Icpm { 10 A("1","长沙"), 11 B("2","福州"), 12 C("3","秦皇岛"), 13 D("4","重庆"), 14 E("5","上海"), 15 F("6","武汉"), 16 G("7","北京"), 17 H("8"), 18 I("9"); 19 20 private String Code = ""; 21 private String Place = ""; 22 private Icpm(String InCode,String InPlace){ 23 this.Code=InCode; 24 this.Place=InPlace; 25 } 26 private Icpm(String InCode){ 27 this.Code=InCode; 28 } 29 30 31 public String GetCode(){ 32 return Code; 33 } 34 public String GetPlace(){ 35 return Place; 36 } 37 38 public void SetCode(String Code){ 39 this.Code=Code; 40 } 41 public void SetPlace(String Place){ 42 this.Place=Place; 43 } 44 45 public Icpm getIcpmPlaceByCode(String TheCode){ 46 Icpm resp = null; 47 if(TheCode==null){ 48 return null; 49 } 50 else{ 51 for(Icpm itor : values()){ 52 if(itor.Code.equals(TheCode)){ 53 resp=itor; 54 break; 55 } 56 } 57 } 58 return resp; 59 } 60 61 62 public Map<String ,String> getResponse(){ 63 Map<String ,String>Response = new HashMap<String ,String >() ; 64 Response.put("respCode",Code); 65 Response.put("respPlace",Place); 66 return Response; 67 68 } 69 }