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

Implement the \"this\" Reference in Transactions.java: public class Transactions

ID: 3791717 • Letter: I

Question

Implement the "this" Reference in Transactions.java:

public class Transactions{

public static void main(String[] args)

{ Account acct1 = new Account("Ted Murphy", 72354, 102.56);

Account acct2 = new Account("Jane Smith", 69713, 40.00);

Account acct3 = new Account("Edward Demsey", 93757, 759.32);

acct1.deposit(25.85);

double smithBalance = acct2.deposit(500.00);

System.out.println("Smith balance after deposit: " + smithBalance);

System.out.println("Smith balance after withdrawal: " + acct2.withdraw (430.75, 1.50));

acct1.addInterest();

acct2.addInterest();

acct3.addInterest();

System.out.println();

System.out.println(acct1);

System.out.println(acct2);

System.out.println(acct3);

}

Explanation / Answer

Account.java

import java.text.NumberFormat;

public class Account {
   //Declaring constant
       private final double RATE = 0.035;
      
       //Declaring instance variables
       private int acctNumber;
       private double balance;
       private String name;

       //Parameterized constructor
       public Account(String name,int acctNumber, double balance ) {
           super();
           this.acctNumber = acctNumber;
           this.balance = balance;
           this.name = name;
       }

       //This method will add the amount to the balance
       public double deposit(double amount) {
           balance = balance + amount;
           return balance;
       }


       //This method will deduct the amount to the balance
       public double withdraw(double amount, double fee) {
           balance = balance - amount - fee;
           return balance;
       }


       //This method will add the interest amount to the balance
       public double addInterest() {
           balance += (balance * RATE);
           return balance;
       }


       //This method will return the balance
       public double getBalance() {
           return balance;
       }

       //toString() method is used to display the contents of an object inside it
       public String toString() {
           NumberFormat fmt = NumberFormat.getCurrencyInstance();
           return acctNumber + " " + name + " " + fmt.format(balance);
       }
}

____________________

Transactions.java

public class Transactions {

   public static void main(String[] args) {
       Account acct1 = new Account("Ted Murphy", 72354, 102.56);
       Account acct2 = new Account("Jane Smith", 69713, 40.00);
       Account acct3 = new Account("Edward Demsey", 93757, 759.32);
       acct1.deposit(25.85);
       double smithBalance = acct2.deposit(500.00);
       System.out.println("Smith balance after deposit: " + smithBalance);
       System.out.println("Smith balance after withdrawal: " + acct2.withdraw (430.75, 1.50));
       acct1.addInterest();
       acct2.addInterest();
       acct3.addInterest();
       System.out.println();
       System.out.println(acct1);
       System.out.println(acct2);
       System.out.println(acct3);

   }

}

______________________

output:

Smith balance after deposit: 540.0
Smith balance after withdrawal: 107.75

72354   Ted Murphy   $132.90
69713   Jane Smith   $111.52
93757   Edward Demsey   $785.90

_____________Thank You