Problem Account Class You are a programmer for the Home JMSB

Problem Account Class You are a programmer for the Home JMSB Bank. You have been assigned to develop a class that models the basic workings of a bank account. The class should have the following properties Balance Holds the current account balance IntRate Interest: Holds the interest earned for the current period. Transactions: Holds the number of transactions for the current period. Holds the interest rate for the period. Write at least three constructors. Include properties for each of the data items. Create a second class that instantiates the first class with information about your account The class should also have the following methods MakeDeposit Takes an argument, which is the amount of the deposit. This argument is added to the Balance property Another method to Display transaction and Display the new balance Sample run JMSB Bank Current Account Details Transaction Number: 3 Current Balance : 1000 .00 Interest Rate: 6.15 Interest Earned: 150.00 Make Deposit Deposit: 100.00 New Balance: 1100.0e Press any key to go to the Account Update Calulator

Solution

//Account.java
public class Account {
  
   //Set constant for interest rate
   public final double INTEREST_RATE=0.15;
   //private variables
   private double balance;
   private double intRate;
   private double interest;
   private int transactions;
  
  
   //constructor
   public Account() {
       balance=0;
       intRate=0;
       interest=0;
       transactions=0;
   }
  
  
   //constructor that takes balance, interest rate and transactions
   public Account(double balance,double intRate,int transactions) {
       this.balance=balance;      
       this.intRate=intRate;
       this.transactions=transactions;
      
       this.interest=balance*intRate ;
   }
  
  
   //constructor
   public Account(double balance,double intRate,
           double interest,int transactions) {
       this.balance=balance;
       this.intRate=intRate;
       this.interest=interest;
       this.transactions=transactions;
   }
  
   //Method to deposit amount into account
   public void deposit(double amt){
       balance=balance+amt;
   }
  
  
  
   //Return interest
   public double getInterest(){
       return interest;
   }
  
  
  
   //Return rate
   public double getRate(){
       return intRate;
   }
  
  
   //Return transactions
   public int getTransaction(){
       return transactions;
   }
  
  
   //Return balance
   public double getBalance(){
       return balance;
   }
  
  
   //Returns string representation of Account object
   public String toString() {
      
       return \"Transaction Number :\"+transactions+
               \"\ Current Balance: \"+balance
               +\"\ Interest Rate :\"+intRate
               +\"\ Interest Earned :\"+getInterest();
   }
}


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


//AccountUpdateCalculator.java
public class AccountUpdateCalculator {  
   public static void main(String[] args) {
      
      
       //Create an instance of Account with balance, rate and transaction number
       Account acount=new Account(1000,
               0.15, 3);
      
       //Set amount =100
       double amount=100;
       ///print account to console
       System.out.println(acount);
      
       //calling makeDeposit method
       acount=makeDeposit(acount, amount);
       //calling displayTransaction method
       displayTransaction(acount, amount);
      
   }
  
  
   /*
   * The method makeDeposit that takes account and amount
   * as argumets and deposit amount to account and return
   * then account object
   * */
   public static Account makeDeposit(Account act,double amount){      
       act.deposit(amount);
       return act;
              
   }
  
   /*
   * The method displayTransaction that takes Account obect and amount
   * and prints deposit and new balance
   * */
   public static void displayTransaction(Account act,double amount)
   {
       System.out.println(\"\ \ Make Deposit\");
       System.out.println(\"Deposit: \"+amount);
       System.out.println(\"New Balance: \"+act.getBalance());
   }
  
  
}

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

Sample Output:

Transaction Number :3
Current Balance: 1000.0
Interest Rate :0.15
Interest Earned :150.0


Make Deposit
Deposit: 100.0
New Balance: 1100.0

 Problem Account Class You are a programmer for the Home JMSB Bank. You have been assigned to develop a class that models the basic workings of a bank account.
 Problem Account Class You are a programmer for the Home JMSB Bank. You have been assigned to develop a class that models the basic workings of a bank account.
 Problem Account Class You are a programmer for the Home JMSB Bank. You have been assigned to develop a class that models the basic workings of a bank account.

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site