Question: In Java Netbeans these are my Account class and CheckingAccount class //the Account class public abstract class Account { //instance variables //private will hide data

In Java Netbeans

these are my Account class and CheckingAccount class

//the Account class

public abstract class Account { //instance variables //private will hide data protected int number; protected String openDate; protected String name; protected double balance; //the constructor

public Account(int number, String openDate, String name, double balance){ this.number = number; this.openDate = openDate; this.name = name; this.balance = balance; }

//get and set instance variables public int getnumber(){ return number; } public void setname(String name){ this.number = number; } public String getopenDate(){ return openDate; } public void setopenDate(){ this.openDate = openDate; } public String getname(){ return name; } public void setname(){ this.name = name; } public double getbalance(){ return balance; } public void setbalance(){ this.balance = balance; }

public void deposit(double amount){ balance = balance + amount; } public boolean withdraw(double amount){ if(amount<=0 || amount>balance) return false; balance -= amount; return true; } public abstract int transferTo(Account account, double amount); public String toString() { String message = "Number:" + number +"<>"+"openDate:" + openDate + "<>"+ "Name:" + name +"<>"+ "Balance:" + balance; return message; }

}//end of class

//the CheckingAccount class

class CheckingAccount extends Account{

public CheckingAccount(int number, String openDate, String name, double balance){ super(number,openDate,name,balance); } public int transferTo(Account account, double amount) { // int res = 0; if (balance>= 10000 && balance >= amount) {withdraw(amount); account.deposit(amount); return 0; } else if (balance <10000 && balance>=amount+2) { withdraw(amount+2); deposit(amount); return 1; } else if (balance <10000 && balance>=amount && balance <=amount+2) { return -1; } else { return -2; } } }

I provide a text file, accounts.txt. You should download this text file into the directory of your Netbeans project. Each row in the file is an account record and is in the format of accountNumber<>openDate<>customerName<>balance, where <> is the partition between two fields and the openDate is in the format of year/month/day. Make sure when reading or writing this text file programmatically, your program uses the file name without an explicit path (so called relative path). For instance, File accountFile = new File("accounts.txt");

this is the account.txt file

1001<>2018/5/1<>Lily Makki<>2085.3 1002<>2018/5/1<>Bran Chan<>14500.05 1003<>2018/5/2<>Hebert Castro<>5698.04 1004<>2018/5/2<>Jane Brown<>4923.12 1005<>2018/5/4<>Alicia Gongalez<>3546.11 1006<>2018/5/15<>Carlos Lopez<>700.06

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.

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.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!