求做一个Java类的设计的题

Account类:代表一个银行账户
balance属性:代表账户里的金额
deposit方法:向账户中存钱,如果传入的金额大于0,存钱,返回true,否则不存钱,返回false
withdraw方法:从账户中取钱,如果余额够,取钱,返回true,如果余额不足,不取钱,返回false
display方法:用于查询当前帐户金额

求大神给看一下 谢谢啦

public class Account {
private double balance;//定义账户的金额
/**
* 存钱
*/
public boolean deposit(double money){
boolean flag = false;
if(money>0.0){
balance+=money;
flag =true;

    }

    return flag;
}
/**
 * 
 * @param money
 * @return
 */
public boolean withdraw(double money){
    boolean flag = false;
    if(money<=this.balance){
        balance-=money;
        flag =true;
    }

    return flag;
}
/**
 * 
 * @param money
 * @return
 */
public double display(){
    return this.balance;
}
public double getBalance() {
    return balance;
}
public void setBalance(double balance) {
    this.balance = balance;
}

}

 class Account{
   //都是整钱
     private int balance;
     public boolean deposit(int money){
        if(money>0.0){
            balance+=money;
                        return true;
                }else{
                    return false;
                }
    }
public boolean withdraw(int money){
    if(money<=this.balance){
        balance-=money;
        return true;
    }
    return false;
}
public int display(){
    return this.balance;
}
 }

1、实现基本功能,代码如下:

// Account类:代表一个银行账户
public class Account {

        // 代表账户里的金额
        private double balance;

        public Account(double amout) {
                balance = amout;
        }

        // 向账户中存钱,如果传入的金额大于0,存钱,返回true,否则不存钱,返回false
        public synchronized boolean deposit(double amount) {
                if (amount > 0) {
                        balance += amount;
                        return true;
                } else {
                        return false;
                }
        }

        // 从账户中取钱,如果余额够,取钱,返回true,如果余额不足,不取钱,返回false
        public synchronized boolean withdraw(double amount) {
                if (balance >= amount) {
                        balance -= amount;
                        return true;
                } else {
                        return false;
                }
        }

        // 用于查询当前帐户金额
        public double display() {
                return balance;
        }

        // 测试Account类
        public static void main(String[] args) throws IOException {
                // 初始化,显示余额
                Account account = new Account(34);
                System.out.println(account.desplay());
                // 存入16,显示余额
                System.out.print(account.deposit(16));
                System.out.println(account.desplay());
                // 存入-1,显示余额
                System.out.print(account.deposit(-1));
                System.out.println(account.desplay());
                // 取出16,显示余额
                System.out.print(account.withdraw(16));
                System.out.println(account.desplay());
                // 取出35,显示余额
                System.out.print(account.withdraw(35));
                System.out.println(account.desplay());
        }
}

2、存钱、取钱的方法都是synchronized修饰的方法,表明它们是同步方法,同步的对象是访问它们的Account对象。

这么做是为了避免在多线程中,多个线程同时取钱、存钱导致程序异常。

使用同步方法,保证每次只能有一个线程存钱或取钱;因为显示余额不会改变balance变量,所以display()方法不需要同步。