zoukankan      html  css  js  c++  java
  • Bank4

    Account:

    package banking4;
    
    public class Account {
        private double balance;
    
        public Account(double int_balance) {
            balance = int_balance;
        }
    
        public double getBlance() {
            return balance;
        }
    
        public boolean deposit(double amt) {
            balance += amt;
            return true;
        }
    
        public boolean withdraw(double amt) {
            if (balance >= amt) {
                balance -= amt;
                return true;
            } else {
                System.out.println("余额不足");
                return false;
            }
        }
    }

    Customer:

    package banking4;
    
    public class Customer {
        private String firstName;
        private String lastName;
        private Account account;
    
        public Customer(String f, String l) {
            firstName = f;
            lastName = l;
        }
    
        public String getFirstName() {
            return firstName;
        }
    
        public String getLastName() {
            return lastName;
        }
    
        public Account getAccount() {
            return account;
        }
    
        public void setAccount(Account acct) {
            account = acct;
    
        }
    
    }

    Bank:

    package banking4;
    
    public class Bank {
    
        private Customer[] customers;// 用于存放客户的
        private int numberOfCustomers;// 记录Customer的个数
    
        public Bank() {
            customers = new Customer[5];
        }
    
        // 添加一个Customer到数组中
        public void addCustomer(String f, String l) {
            Customer cust = new Customer(f, l);
            customers[numberOfCustomers] = cust;
            numberOfCustomers++;
        }
    
        // 获取Customer的个数
        public int getNumberofCustomer() {
            return numberOfCustomers;
        }
    
        // f返回指定索引位置Customer
        public Customer getCustomer(int index) {
            return customers[index];
        }
    }

    TestBanking4:

    package TestBanking;
    /*
     * This class creates the program to test the banking classes.
     * It creates a new Bank, sets the Customer (with an initial balance),
     * and performs a series of transactions with the Account object.
     */
    
    import banking4.*;
    
    public class TestBanking4 {
    
      public static void main(String[] args) {
        Bank  bank = new Bank();
    
        // Add Customer Jane, Simms
       bank.addCustomer("Jane", "Simms");
        //code
        //Add Customer Owen, Bryant
       bank.addCustomer("Owen", "Bryant");
        //code
        // Add Customer Tim, Soley
       bank.addCustomer("Tim", "Soley");
        //code
        // Add Customer Maria, Soley
       bank.addCustomer("Maria", "Soley");
        //code
        for ( int i = 0; i < bank.getNumberofCustomer(); i++ ) {
          Customer customer = bank.getCustomer(i);
    
          System.out.println("Customer [" + (i+1) + "] is "
                 + customer.getLastName()
                 + ", " + customer.getFirstName());
        }
      }
    }

    输出结果:

    Customer [1] is Simms, Jane
    Customer [2] is Bryant, Owen
    Customer [3] is Soley, Tim
    Customer [4] is Soley, Maria

     
    All that work will definitely pay off
  • 相关阅读:
    语言模型的压缩方法
    推荐算法之 Slope One 算法
    基于内容的推荐(Contentbased Recommendations)
    Txt文件转换为Excel文件
    WebResource 内嵌资源
    多层模态窗口showModalDialog页面提交及刷新
    屏蔽/自定义JavaScript脚本错误
    .net动态显示当前时间
    客户端自动累加
    中国IT管理之窥豹一斑
  • 原文地址:https://www.cnblogs.com/afangfang/p/12487817.html
Copyright © 2011-2022 走看看