您的位置:首页 > 编程语言 > Java开发

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

2017-08-07 19:43 531 查看
这是我在初学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新手测试。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  java