JAVA项目:简单的银行账户系统1

这是我在初学Java的第一个实战项目,在很多视频也有相关的介绍,
这是非常适合新手的一个简单的代码。
这里就不赘述,直接上代码!

Account类的编译模块
这里主要是对客户的基本账户操作:

public class Account {
    private double balance;//账户余额

    public Account(double init_balance) {
        // TODO Auto-generated constructor stub
        balance = init_balance;
    }

    public double getBalance(){
        return balance;
    }

//  存钱
    public void desposit(double amt){//存钱数
        balance+=amt;
    }

//  取钱
    public void withdraw(double amt){//取钱数(当余额不足时提醒)
        if(balance>=amt){
        balance-=amt;
        }else{
            System.out.println("余额不足!");
        }
    }
}

在基本的操作完成后我们要进行测试,下面是测试代码:

import Banking1.Account;

public class testbanking1 {

        public static void main(String[] args){
            Account account;

//          Create an account that can has a 500.00 balance
            account = new Account(500.00);
            System.out.println("Create an account that can has a 500.00 balance");

//          code
            account.withdraw(150);
            System.out.println("Withdraw 150.00");
//          code
            account.desposit(22.50);
            System.out.println("Deposit 22.50");

//          code
            account.desposit(47.62);
            System.out.println("Withdraw 47.62");
//          code
//          Print out the final account balance
            System.out.println("The account has a balance of "+account.getBalance());

        }
}

这是最简单的一个小项目,但值得练手,适合初入的java新手测试。

  • 2
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值