少年阿賓

          那些青春的歲月

            BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
            500 Posts :: 0 Stories :: 135 Comments :: 0 Trackbacks

          package com.abin.inter.service;

          public interface UserService {
           
           public static enum UserType{
            UserBasic("Basic Information"),
            UserName("Name Of User"),
            UserSex("Sex Of User"),
            UserAge("Age Of User"),
            UserInitialize("Initialize Of User");
            
            private String info;
            private UserType(String _info){
             this.info=_info;
            }
            
            public String getObject(){
             return info;
            }
           };
           
           
           int UserSum(int one,int two,UserType userInfo);
           String Welcome(String username,UserType userInfo);
          }







          package com.abin.inter.serviceImpl;

          import com.abin.inter.service.UserService;

          public class UserServiceImpl implements UserService{
           @Override
           public int UserSum(int one, int two,UserType userInfo) {
            UserType user=UserType.UserInitialize;
            System.out.println("Enum Info:"+user.getObject());
            if(userInfo.equals(UserType.UserAge)){
             System.out.println("UserInfo:"+userInfo);
             return one+two;
            }
            return 0;
           }

           @Override
           public String Welcome(String username,UserType userInfo) {
            UserType user=UserType.UserInitialize;
            System.out.println("Enum Info:"+user);
            if(userInfo.equals(UserType.UserName)){
             System.out.println("UserInfo:"+userInfo);
             return "歡迎"+username;
            }
            return "NOT WELCOME";
           }

           @Override
           public String toString() {
            // TODO Auto-generated method stub
            return super.toString();
           }
           
           
          }








          package com.abin.inter.test;

          import com.abin.inter.service.UserService;
          import com.abin.inter.service.UserService.UserType;
          import com.abin.inter.serviceImpl.UserServiceImpl;

          import junit.framework.TestCase;

          public class TestUser extends TestCase{
           
           public void test(){
            UserService service=new UserServiceImpl();
            UserType userInfo=UserType.UserAge;
            int result=service.UserSum(10, 17, userInfo);
            System.out.println("UserSum="+result);
            UserType userInfo1=UserType.UserName;
            String result1=service.Welcome("abin", userInfo1);
            System.out.println("Welcome="+result1);
            
           }
          }





          運行結果:
          Enum Info:Initialize Of User
          UserInfo:UserAge
          UserSum=27
          Enum Info:UserInitialize
          UserInfo:UserName
          Welcome=歡迎abin
          posted on 2012-03-12 22:29 abin 閱讀(648) 評論(0)  編輯  收藏 所屬分類: java集合類
          主站蜘蛛池模板: 广宗县| 隆回县| 天镇县| 白城市| 资溪县| 贵南县| 汉川市| 赤城县| 邹平县| 平江县| 长寿区| 开阳县| 宣汉县| 若尔盖县| 神木县| 郸城县| 漳浦县| 兰西县| 怀安县| 新龙县| 汶川县| 阳春市| 开化县| 秦安县| 岳阳市| 响水县| 连山| 永城市| 汾西县| 雷州市| 桃园县| 宁海县| 浠水县| 镇远县| 阿荣旗| 普兰店市| 大竹县| 白玉县| 共和县| 青海省| 汪清县|