少年阿宾

那些青春的岁月

  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 阅读(636) 评论(0)  编辑  收藏 所属分类: java集合类

只有注册用户登录后才能发表评论。


网站导航: