السلام عليكم
والله كتبت برنامج مطلوب منا حله وغالبا الاختبار بيكون حوله..
احتجت مساعدتكم فياليت ماتردوني
وشكرا مقدما..
--------------
كتبت البرنامج
public class BankAccount{
private double balance;
public BankAccount(){
balance = 0;}
public BankAccount(double b){
balance = b;}
public void deposit(double amount){
balance += amount;}
public void withdraw(double amount){
balance -= amount;}
public double getBalance(){
return balance;}
public void transfer(BankAccount other , double amount){
withdraw(amount);
other.deposit(amount);}
}
public class CheckAccount extends BankAccount{
private int tranCount;
private static final int FREE_TRANSACTION=3;
private static final double TRANSACTION_FEE =2.0;
//---------------------------------------------------------
public CheckAccount(int b){
super(b);
tranCount=0;
}
public void deposit(double amount){
tranCount++;
super.deposit(amount);
}
public void withdraw(double amount){
tranCount++;
super.withdraw(amount);
}
public void deductFrees(){
if (tranCount > FREE_TRANSACTION)
{ double fees = TRANSACTION_FEE *
(tranCount - FREE_TRANSACTION);
super.withdraw(fees);
}
tranCount =0;
}
}
//---------------------------------------------------------
public class ATest{
public static void main(String args[])
{
CheckAccount ahmedChecking = new CheckAccount();
ahmedChecking.deposit(500);
ahmedChecking.withdraw(80);
ahmedChecking.withdraw(400);
ahmedChecking.deposit(400);
ahmedChecking.withdraw(250);
endOfMonth(ahmedChecking){
printBalance("Ahmed's Checking", ahmedChecking);
}
public static void endOfMonth(CheckAccount Checking){
Checking.deductFees();
}
public static void printBalance(String name,BankAccount account)
{ System.out.println("The balance of "+ name
+"account is $" + account.getBalance() );
}
}
}