银行java技术_JAVA之银行系统1

实现银行系统的账目,增加金额,与减少金额。

当支付金额小于实际金额时,返回假。当增加金额成功时,为真。public class Account {

private double balance;

public double getBalance() {

return balance;

}

public Account(double balance) {

super();

this.balance = balance;

}

public boolean deposit(double amt){

balance += amt;

return true;

}

public boolean withdraw(double amt){

if(balance < amt){

return false;

}

balance -=amt;

return true;

}

}

实现银行系统客户类,并包含了账目类,引用同一片内存区域public class Customer {

private String firstName;

private String lastName;

private Account account;

public Customer(String firstName, String lastName) {

super();

this.firstName = firstName;

this.lastName = lastName;

}

public Account getAccount() {

return account;

}

public void setAccount(Account account) {

this.account = account;

}

public String getFirstName() {

return firstName;

}

public String getLastName() {

return lastName;

}

}

实现银行类,并包含了客户数组,以及客户数组下标的标识变量public class Bank {

private Customer []customers;

private int numberOfCustomers;

//初始化customer数组

public Bank()

{

customers=new Customer[100];

}

//依次添加客户

public void addCustomer(String f,String l){

Customer customer=new Customer(f,l);

customers[numberOfCustomers]=customer;

numberOfCustomers++;

}

public int getNumberOfCustomers() {

return numberOfCustomers;

}

public Customer getCustomer(int index){

return customers[index];

}

}

依次添加客户信息,并读出public static void main(String[] args) {

Bank bank=new Bank();

bank.addCustomer("Jane", "Smith");

bank.addCustomer("Owen", "Bryant");

bank.addCustomer("Tim", "Soley");

bank.addCustomer("Maria", "Soley");

for(int i=0;i

{

Customer customer=bank.getCustomer(i);

System.out.println("Customer ["+(i+1)+"]"+

"is "+customer.getLastName()+

","+customer.getFirstName());

}

}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值