14 回答

TA貢獻(xiàn)24條經(jīng)驗 獲得超19個贊
public class UserInfo{
????@NotNull
????@Size(min=1,max=5)
????private String name;
????@NotNull
????@Pattern(regexp="[男女]{1}")
????private String sex;
????@NotNull
????@Pattern(regexp="[0-9xX]{18}")
????private String idcard;
????@NotNull
????@Pattern(regexp="[0-9]{11}")
????private String phone;
????getter....
????setter...
}
public class Account{
????@NotNull
????private String uid;
????@NotNull
????@Min(0)
????private BigDecimal balance;
????@NotNull
????@Pattern(regexp="[0-9]{6}")
????private String password;
????@NotNull
????@Valid
????private UserInfo userInfo;
????getter...
????setter...
????public boolean save(double money){
????????synchronized(this){
?????????????this.balance=balance.add(BigDecimal.valueOf(money));
???????? }
????????return true;
????}
????public boolean draw(double money){
????????if(money<=balance.doubleValue()){
????????????synchronized(this){
???????????????????this.balance=balance.subtract(BigDecimal.valueOf(money));
?????????????}
????????return true;
????????}else{
?????????return false;
????????}
????public String modifyPwd(String newPwd){
????????this.password=newPwd.matches("[0-9]{6}")?newPwd:password;
????????return this.password.equals(newPwd)?"修改成功":"請輸入格式正確的密碼";
????}
????????public boolean modifyPhone(String newPhone){
????????????userInfo.setPhone(newPhone);
????????????return true;
????????}
????}
}
編寫代碼不容易,getter和setter自己用eclipse生成一下就可以了

TA貢獻(xiàn)4條經(jīng)驗 獲得超4個贊
這是一個封裝的類,因為將來真正開始開發(fā)以后,好多數(shù)據(jù)是不可以直接展示給客戶的,那么我們就要將這些數(shù)據(jù)給封裝起來,留一個相關(guān)的seter方法用于設(shè)置值,用gettetr方法來取值?。?!

TA貢獻(xiàn)90條經(jīng)驗 獲得超70個贊
class?UserInfo{ ????//自己判斷 ????private?String?name; ????private?Char/String?sex; ????.... ????get+set方法 ???? ???? }
class Account{
//屬性同上
????public boolean save(int ....){
????}
? ? draw()
????...方法
}
添加回答
舉報