Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can someone please help me with this? I\'m stumped.. Create an Account class (Ac

ID: 672794 • Letter: C

Question

Can someone please help me with this? I'm stumped..

Create an Account class (Account.java) that a bank might use to represent a customer's bank account. Specification Include a private variable of type int to represent the account balance.

Provide a constructor that has a parameter for initial balance and uses it to initialize the account balance.

Provide 3 member functions: credit - adds an amount passed as an argument to the current balance. debit - withdraws an amount passed as an argument from the current balance. getBalance - returns the balance amount.

Create a program (AccountTest.java) that creates two Account objects and validate the methods of the class Account. (Call the methods passing the appropriate values to make sure they produce the expected results.)

Explanation / Answer

/**The Account class contains constructor to set balance
* amount. The method credit adds the amount to the balance.
* The method debit subtracts the amount from the balance
* The method getBalance returns the balance of Account*/
//Account.java
public class Account
{
   //private member variable balance
   private double balance;
  
   //No argument constructor to set balance to zero
   public Account()
   {
       balance=0;
   }
  
   //Parameter constructor to set balance
   public Account(double balance)
   {
       this.balance=balance;
   }
  
   /*The method credit that takes double amount and
   * then add the amount to the balance*/
   public void credit(double amount)
   {
       this.balance=this.balance+amount;
   }
  
   /*The method debit that takes double amount and
   * then subtracts from the balance*/
   public void debit(double amount)
   {
       this.balance=this.balance-amount;
   }
  
   //Returns the balance of Account
   public double getBalance()
   {
       return balance;
   }
  
}   //end of the class Account


---------------------------------------------------------------------------------------------------------------------------------------------------

/**The class AccountTest that test the class Account.
* Create two instances of Account class test the methods
* and print expected and real output*/
//AccountTest.java
public class AccountTest
{
   public static void main(String[] args)
   {
      
       /*Create two instances of Account class with
          intialil balance.*/
       Account accountObjec1=new Account(500);
       Account accountObjec2=new Account(1000);
      
       /*Call credit method to add balance to the
       account objects */      
       accountObjec1.credit(500);
       accountObjec2.credit(500);
      
      
       /*Call debit method to add balance to the
       account objects */      
       accountObjec1.debit(200);
       accountObjec2.debit(200);
      
       //print the expected results
       System.out.println("Expected Output");
       System.out.println("Account 1 object ");
       System.out.println("Balance : "+800);
       System.out.println("Account 2 object ");
       System.out.println("Balance : "+1300);
      
       //print program actual results
       System.out.println("Program Output");
       System.out.println("Account 1 object ");
       System.out.println("Balance : "+accountObjec1.getBalance());
       System.out.println("Account 2 object ");
       System.out.println("Balance : "+accountObjec2.getBalance());
      
      
   }
}


------------------------------------------------------------------------------------------------------------------------------

Sample Output:

Expected Output
Account 1 object
Balance : 800
Account 2 object
Balance : 1300
Program Output
Account 1 object
Balance : 800.0
Account 2 object
Balance : 1300.0