Question
This is part 1. Need help with this hw. this is my Account class. need help with CheckingAccount as well. public class Account { private
This is part 1.
Need help with this hw. this is my Account class. need help with CheckingAccount as well.
public class Account { private int number; private String name; private String openDate; private double balance;
public Account(int number, String name, String openDate, double balance) { this.number = number; this.name = name; this.openDate = openDate; this.balance = balance; }
public void withdraw(double amount) { if(this.balance > amount){ this.balance -= amount; } }
public void deposit(double amount) { this.balance += amount; }
public void transferTo(Account other, double money){ withdraw(money); other.deposit(money); }
@Override public String toString() { return "Account{" + "number=" + number + ", name='" + name + '\'' + ", openDate='" + openDate + '\'' + ", balance=" + balance + '}'; } }
1. Account and CheckingAccount classes
CheckingAccount (5 points)
This is a child class of Account and implements the transferTo() method as follows.
public int transferTo(Account account, double amount): the first argument is the beneficiary account, and the second argument is the transfer amount. This method transfers the money from this current account to the beneficiary account, and returns
0: transfer is successful and a $2 transfer fee is not applied
1: transfer is successful and the $2 transfer fee is applied
-1: transfer is unsuccessful because balance is less than transfer amount and $2 transfer fee
-2: transfer is unsuccessful because balance is less than transfer amount
For our projects, the business rules are:
? If the balance of transferring account is $10000 or higher, a $2 transfer fee is waived.
? When making a transfer to a beneficiary account, if the balance of the transferring account is less than $10000, $2 transfer fee is deducted from the balance when the transfer occurs.
? If the balance is not sufficient to cover transfer amount (and the $2 transfer fee if the fee applies), the transfer should not occur.
public CheckingAccount(int nu, String na, String op, double ba): is a constructor and uses passed-in arguments to initialize instance variables.
In the part 2, you re-use the Account and CheckingAccount classes from the prior part 1. So in addition to these two classes from the part 1 and the provided accounts.txt file, your part 2 project includes the following AccountUtility and TestPart2 classes.
accounts.txt
10012018/5/1Lily Makki2085.3 10022018/5/1Bran Chan14500.05 10032018/5/2Hebert Castro5698.04 10042018/5/2Jane Brown4923.12 10052018/5/4Alicia Gongalez3546.11 10062018/5/15Carlos Lopez700.06
AccountUtility
-listNumbers: ArrayList
-mapNumAccounts: LinkedHashMap
+AccountUtility()
+readFile(): void
+getListNumbers(): ArrayList
+getMapNumAccounts(): LinkedHashMap
+saveFile(LinkedHashMap): void
1. AccountUtility class
This class has methods to read a provided file, accounts.txt, update the file, and provide data from the accounts.txt for other program(s).
1.1 Constructor (2 points)
public AccountUtility(): The constructor initializes the two instance variables.
1.2 Read the given text file (10 points)
public void readFile(): reads accounts.txt file and populates all account numbers into listNumbers ArrayList, and adds account numbers and corresponding CheckingAccount object as records to the LinkedHashMap object, mapNumAccounts.
1.3 Get account numbers (1 point)
public ArrayList getListNumbers(): returns the instance variable, listNumbers.
1.4 Get LinkedHashMap objects (1 point)
public LinkedHashMap getMapNumAccounts(): returns the instance variable, mapNumAccounts.
1.5 Save content to the text file (6 points)
public void saveFile(LinkedHashMap map): the pass-in parameter is a LinkedHashMap object in which the keys are account numbers and values are CheckingAccount objects. This method writes content from the passed-in LinkedHashMap object to accounts.txt, overwrites the files entire old content.
2. TestPart2 class (10 points)
This class has the main() method.
You create an AccountUtility object in this class, and use the object to test readFile() and getListNumbers(), and use System.out.println() to clearly display all account numbers retrieved from the accounts.txt file.
Using the above AccountUtility object to call getMapNumAccounts() method and assign the returned value to a LinkedHashMap object.
You must modify balances of two different accounts from the LinkedHashMap object by calling deposit(), withdraw(), and transferTo() methods with hard-code values.
You call the saveFile(LinkedHashMap) method to overwrite the accounts.txt file. The pass-in parameter is the above updated LinkedHashMap object.
Notes:
1) When I test your project, my accounts.txt will follow the same format as yours but have different content.
2) AccountUtility should be the only class in the project that defines methods to read from and write to the accounts.txt file.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started