第四讲 eclipse高级操作1 重构 代码 public class Test1 { public int calccost(User user) { if(user.usertype==null) throw new IllegalArgumentException("usertype不能为空"); if(user.amount<=0) throw new IllegalArgumentException("amount must greater 0"); int ret=0; if(user.usertype.equals("normal")) ret=add(user.amount,10); else if(user.usertype.equals("vip")) ret=add(user.amount,8); else throw new IllegalArgumentException("usertype error:"+"normal" +","+"vip"); return ret; } private int add(int i1,int i2) { return i1+i2; } public static void main(String[] args) { String userName="tom"; String userType="normal"; int amount=20; User user=new User(); user.username=userName; user.usertype=userType; user.amount=amount; System.out.println(new Test1().calccost(user)); } }