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
  • 相关阅读:
    Spark Locality Sensitive Hashing (LSH)局部哈希敏感
    Spark ChiSqSelector 卡方选择器
    图解开源协议
    如何使用Hasu USB to USB Controller Converter刷写tmk固件交换Caps和Ctrl
    使用PHP读取PHP文件并输出到屏幕上
    Mac修改显示器使支持原生缩放
    PHP中使用PDO的预处理功能避免SQL注入
    如何做数据库分页查询
    Chrome报错提示Unchecked runtime.lastError: The message port closed before a response was received.
    Parallels Desktop虚拟机无法关机提示“虚拟机处理器已被操作系统重置”
  • 原文地址:https://www.cnblogs.com/afangfang/p/12487817.html
Copyright © 2011-2022 走看看