Vous êtes sur la page 1sur 2

// Khai bao class CustomerAccount class CustomerAccount { // Khai bao 2 bien accountType va balance; int accountType; double balance;

// Khai bao hm dung hai tham so: 1 la account type va 1 la balance tuong ung voi moi account // Khai bao method getAccountType(); // Khai bao method getBalance(); // Khai bao method setBalance(); } // Khai bao class TransferManager thuc hien cac cong viec trong moi lan transfer class TransferManager implements Runnable { // Khai bao 2 CustomerAccount ca1, ca2; // Khai bao hai bien: //m -la so tien duoc transfer trong moi giao dich, // bien count de dem so lan transfer // Khai bao constructor public TransferManager(CustomerAccount c1, CustomerAccount c2, int n) { // ...... } // Overrride method run() public void run() { Lap toi da so lan transfer // Gia su so lan transfer toi da la 3 { // Khai bao 3 bien: bl1, bl2 luu giu balance cua moi acc ount, blt luu giu tong balance cua 2 account // Xuat thong tin account va balance cua 2 account ca1 v a ca2 truoc khi transfer; // Tinh tong balance v xuat tong balance cua 2 account tr uoc khi transfer; // Xuat thong tin so luong tien duoc transfer // Tinh balance con lai cua moi account sau khi transfer ; // Xuat thong tin account va balance cua 2 account ca1 v a ca2 sau khi transfer; // Tinh tong balance v xuat tong balance cua 2 account sa u khi transfer; // Cho Thread vao trang thai sleep va tang bien count so lan transfer; } } } // Class AccountManager_Ass1 duoc coi la class dung de kiem tra hai class tren. public class AccountManager_Ass1 {

public static void main(String[] args) { // Khoi tao 4 Customer account: acc1, acc2, acc3, acc4; // Khai bao bien luu giu tong balance cua cac account; // Tinh tong balance truoc khi thuc hien transfer va xuat gia tri tong t inh duoc; // Thuc hien transfer cho moi cap accounts: Khoi tao hai bien cua class TransferManager // (tm1: acc1 -> acc2, tm2: acc3 -> acc4) // Tao 2 Thread cho moi TransferManager v start chung; // Cho 2 Thread join; // Tinh tong balance truoc khi thuc hien transfer va xuat gia tri tong t inh duoc - XEM KET QUA VA SO SANH VOI TRUOC TRANSFER } }