15 สิงหาคม 2554

[JAVA]โปรแกรมจำลองระบบธนาคาร แบบฝึกหัดที่ 5.1


---------- Account Class ----------

package Banking;

public class Account {
    private double balance;
    public Account(double amount){
        balance = amount;
    }
    public void deposit(double amount){
        balance = balance + amount;
    }
    public void withdraw(double amount){
            balance = balance - amount;
    }
    public double getBalance(){
        return balance;
    }
    public void showBalance(){
        System.out.println(balance);
    }
    public Account(){
     
    }
}


---------- Customer Class ----------

package Banking;

public class Customer {
    private String firstName;
    private String lastName;
    private Account acct;

    public Customer(String fName,String lName){
        firstName = fName;
        lastName = lName;
    }
    public void setFirstName(String fName){
        firstName = fName;
    }
    public String getFirstName(){
        return firstName;
    }
    public void setLastName(String lName){
        lastName = lName;
    }
    public String getLastName(){
        return lastName;
    }
    public void setAccount(Account acct){
        acct = acct;
    }
    public Account getAccount(){
        return acct;
    }
}

---------- Teller Class ----------

import Banking.*;

public class Teller {
    public static void main(String args[]){
        boolean result;
        Account myAccount = new Account(4000);
        Customer cust = new Customer("Somchai","Sommut");
        cust.setAccount(myAccount);
        result = myAccount.withdraw(3000);
        myAccount.deposit(4200);
        myAccount.showBalance();
        System.out.println("Withdraw = "+result);
        System.out.println(cust.getFirstName()+" "+cust.getLastName());
    }  
}

ไม่มีความคิดเห็น:

แสดงความคิดเห็น