السلام عليكم
صباح الخير
أتمنى من أخوتى أن يسعدونى أنا عندى برنامج وأريد أن أقوم بعمليه الاستدع فى main هذا هوى البرنامج
ولكن يوجد فيه أخطأ أريد منكم الملاحظات وتوجيه
وشكرا.
import java.io.*;
public class Account
{
// Data members
public long user_ID; // attribute (data)
public int accountNumber; // attribute (data)
public int balance = 0; // attribute (data)
//Constructors
public Account() {
user_ID = 0;
accountNumber = 0;
balance = 0;
}
public Account( long i, int accountNumber, int balance) {
this.user_ID=i;
this.accountNumber = accountNumber;
this.balance = balance;
}
// Public functions
public int withdraw (int amount) // method
{
balance -= amount;
}
void deposit (int amount)
{
balance += amount;
}
int showBalance ()
{
System.out.println("Your balance is " + balance);
return (balance);
}
import java.util.Scanner;
public class AccountTest{
public static void main (String argv[]) {
Account B = new Account () ;
B. Account R( 0, 0, 0);
B. Account r(76523122, 12345, 25000);
B. withdraw r(6000);
B. deposit R(1000);
B. showBalance(R,r);
B. showBalance®;
B. showBalance®;
B. withdraw r(2000);
B. deposit r(2800);
B. showBalance®;
}// end main
}// end class
وهذا السؤال
Modify the withdraw method in the account class such that
• It withdraws money from the account only if the amount to be
withdrawn is less than the balance and less than 5000. If he
amount is greater than 5000, the function displays a message
stating that the maximum amount to be withdrawn is 5000. If
the amount is greater than the balance, it displays a message
saying amount is more than the balance. In both cases it
returns without changing the balance.
• If the amount is both more than 5000 and more than the
balance, it is enough to display a statement saying the
maximum amount to be withdrawn is 5000.
• If the user_ID is a zero, it must display a message stating that
this is an invalid account.
• Modify every function that accesses the account to check if the
user_ID is zero; it displays the same message as above and
returns right away. From now one, every access to an invalid
account should display such a message and does not change
anything in the account.
Create a subclass of Account called SavingAccount. The Saving
Account class should have an interestRate variable (double) (for
example 0.04 to represent 4% interest).
• The constructor of the Saving Account should use the
constructor of the Account class and sets the interest rate to
0%.
• Add a method called setInterest to set the interest rate to
the required value. This method should confirm setting the
interest rate by printing a statement like “the interest rate for
account xxxx is now y%”
• Add a method called addInterest that calculates the amount of
interest on the balance and add it to the balance (note that
the balance is an integer).
• Override the showBalance method to show both the balance
and the interest rate of the saving account.
Write a driver class called testAccount to do the following
• creates a saving account object with user_ID 0, account
number of 0, and a balance of 0.
• Create another saving account with user_ID=76523122,
account number of 12345 and balance of 25000
• withdraw 6000 Rials from the second account
• deposit 1000 Rials in the first account.
• Set the interest rate to both first and second account to 4%
• Add interest to the second account
• Show the balance of the second account.
• Withdraw 2000 SR from the second account
• Deposit 2800 SR to the second account
• Show the balance of the second account


