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

I UPVOTE ALL ANSWERS, thank you for your work. Please follow all instructions ex

ID: 3714880 • Letter: I

Question

I UPVOTE ALL ANSWERS, thank you for your work. Please follow all instructions exactly, I will upvote:

The Transaction class is as follows:

This is the transaction test class, I do not believe you need it, believe you only need the Transaction class to do the required but here it is in case:

You are required to create a NetBeans project modeled arter a banking situation. First, create the projec named as HWSYourFirstNameLastName. Check to create the main class, which will create a package under Source Packages, named after your project name, and open the main class containing the main method. Next, copy and paste the Transaction class from your HW4 into this package using NetBeans' Refactor feature. If not using Refactor, just copy and paste the Transaction class into this package, then open the Transaction class and update its first line of code by changing the package name to its current package name. For this project, you are required to create two classes other than the Transaction class: an Account class (whereas an account may incur multiple transactions) and the main class (containing the main method). Please closely follow the requirements below. Requirements for the Account class: You need to create the Account class as an independent file in the same package of your main class Class data fields: A private data field of int data type, representing the id of the account. A private data field of String data type, representing the name of the customer A private data field of double data type, representing the balance of the account. A private data field of double data type, representing the annual interest rate. Key assumptions: (1) all accounts created following this class construct share the same interest rate. (2) While the annual interest rate is a percentage, e, g., 4.5%, but for simplicity users will just enter the double number as 4.5 (not 0.045). Therefore, you, the code developer, need to divide the annual interest rate by 100 whenever you use it in a calculation A private data field of Date data type, representing the account creating date. A private data field of ArrayList data type, representing a list of transactions for the account. Each element of this ArrayList must be an instance of the Transaction class defined in HW4 (the Transaction class has been copied into the current package)

Explanation / Answer

Hello, I have answered a similar question before, so I’m referring it here with proper changes to work according to your needs. Everything is implemented exactly as specified, including comments explaining each important statements. Drop a comment if you have any doubts. Thanks.

// Account.java

import java.util.ArrayList;

import java.util.Date;

public class Account {

                private int id;

                private String name;

                private double balance;

                private static double annualInterestRate;

                private Date createdDate;

                private ArrayList<Transaction> transactions;

                /**

                * Constructor with no arguments

                */

                public Account() {

                                id = 0;

                                name = "";

                                balance = 0;

                                createdDate = new Date();

                                transactions = new ArrayList<Transaction>();

                }

                /**

                * Constructor with account id and starting balance as arguments

                */

                public Account(int id, double balance) {

                                this.id = id;

                                this.balance = balance;

                                name = "";

                                createdDate = new Date();

                                transactions = new ArrayList<Transaction>();

                }

                /**

                * Constructor with id, name and balance as arguments

                */

                public Account(int id, String name, double balance) {

                                this.id = id;

                                this.balance = balance;

                                this.name = name;

                                createdDate = new Date();

                                transactions = new ArrayList<Transaction>();

                }

                /**

                * Required accessors and mutators

                */

                public int getId() {

                                return id;

                }

                public void setId(int id) {

                                this.id = id;

                }

                public double getBalance() {

                                return balance;

                }

                public void setBalance(double balance) {

                                this.balance = balance;

                }

                /**

                * method to get annual interest rate, common for all accounts, so made it

                * static.

                */

                public static double getAnnualInterestRate() {

                                return annualInterestRate;

                }

                /**

                * method to set annual interest rate, common for all accounts, so made it

                * static.

                */

                public static void setAnnualInterestRate(double annualInterestRate) {

                                Account.annualInterestRate = annualInterestRate;

                }

                public String getName() {

                                return name;

                }

                public Date getCreatedDate() {

                                return createdDate;

                }

                public ArrayList<Transaction> getTransactions() {

                                return transactions;

                }

                /**

                * method to calculate and return the monthly interest

                */

                public double getMonthlyInterest() {

                                double monthlyInterestRate = annualInterestRate/ 1200.0;

                                double monthlyInterest = balance * monthlyInterestRate;

                                return monthlyInterest;

                }

                /**

                * method to withdraw money and log the transaction

                */

                public void withdraw(double amount, String description) {

                                balance -= amount;

                                Transaction transaction = new Transaction('W', description, amount,

                                                                balance);

                                transactions.add(transaction);

                }

                /**

                * method to deposit money and log the transaction

                */

                public void deposit(double amount, String description) {

                                balance += amount;

                                Transaction transaction = new Transaction('D', description, amount,

                                                                balance);

                                transactions.add(transaction);

                }

}

// Transaction.java

import java.util.Date;

public class Transaction {

                // Data members

                private Date date;

                private char type;

                private double amount, balance;

                private String description;

                // Parametrized constructor to initialize fields

                public Transaction(char type, String description, double amount,

                                                double balance) {

                                this.date = new Date();

                                this.type = type;

                                this.amount = amount;

                                this.balance = balance;

                                this.description = description;

                }

                // Accessor methods

                public Date getDate() {

                                return date;

                }

                public char getType() {

                                return type;

                }

                public double getAmount() {

                                return amount;

                }

                public double getBalance() {

                                return balance;

                }

                public String getDescription() {

                                return description;

                }

                public String toString() {

                                String typeOfTrans;

                                // If type is D, its deposit else withdrawl

                                if (type == 'D') {

                                                typeOfTrans = "Deposit";

                                } else {

                                                typeOfTrans = "Withdrawal";

                                }

                                // Return string contain details of transaction

                                return "Type of Transaction: " + typeOfTrans + " " +

                                "Date of Tansaction: " + date + " " +

                                "Description: " + description + " " +

                                "Balance: " + balance + " " +

                                "Amount: " + amount + " ";

                }

}

// Main.java

public class Main {

                public static void main(String[] args) {

                                /**

                                * Setting the annual interest rate

                                */

                                Account.setAnnualInterestRate(1.5d);

                                /**

                                * creating an account with id -1122 , name George and initial balance

                                * of 1000

                                */

                                Account acc = new Account(1122, "George", 1000);

                                /**

                                * performing some deposits

                                */

                                acc.deposit(30, "Gift");

                                acc.deposit(40, "bonus");

                                acc.deposit(50, "Salary");

                                /**

                                * performing some withdrawals

                                */

                                acc.withdraw(5, "Rent");

                                acc.withdraw(4, "Food");

                                acc.withdraw(2, "Recharge");

                                /**

                                * displaying account summary

                                */

                                System.out.println("Name: " + acc.getName());

                                System.out.println("Annual Interest Rate: "

                                                                + Account.getAnnualInterestRate());

                                System.out.println("Balance: " + acc.getBalance());

                                System.out.println("Monthly Interest: " + acc.getMonthlyInterest());

                                System.out.println("Created Date: " + acc.getCreatedDate().toString());

                                System.out.println("Transactions:");

                                for (Transaction t : acc.getTransactions()) {

                                                System.out.println(" " + t);

                                }

                }

}

/*OUTPUT*/

Name: George

Annual Interest Rate: 1.5

Balance: 1109.0

Monthly Interest: 1.38625

Created Date: Tue Apr 24 11:22:29 IST 2018

Transactions:

Type of Transaction: Deposit

Date of Tansaction: Tue Apr 24 11:22:29 IST 2018

Description: Gift

Balance: 1030.0

Amount: 30.0

Type of Transaction: Deposit

Date of Tansaction: Tue Apr 24 11:22:29 IST 2018

Description: bonus

Balance: 1070.0

Amount: 40.0

Type of Transaction: Deposit

Date of Tansaction: Tue Apr 24 11:22:29 IST 2018

Description: Salary

Balance: 1120.0

Amount: 50.0

Type of Transaction: Withdrawal

Date of Tansaction: Tue Apr 24 11:22:29 IST 2018

Description: Rent

Balance: 1115.0

Amount: 5.0

Type of Transaction: Withdrawal

Date of Tansaction: Tue Apr 24 11:22:29 IST 2018

Description: Food

Balance: 1111.0

Amount: 4.0

Type of Transaction: Withdrawal

Date of Tansaction: Tue Apr 24 11:22:29 IST 2018

Description: Recharge

Balance: 1109.0

Amount: 2.0