Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using the text file attached and the class Account.java, first read the text file accounts.txt and use the information to create a List (ArrayList or

Using the text file attached and the class Account.java, first read the text file accounts.txt and use the information to create a List (ArrayList or LinkedList- your choice) for Account objects.

Next, using the library class DataOutputStream and its associated File classes, open a binary file named accounts.bin and write the information in each account object to the new file. The order of information written should match the order in the accounts.txt, but write using the methods of DataOutputStream.

public class Account { // attributes protected int accountNumber; protected String accountHolderName; protected double balance; protected String accountType; // constructor // note that there is not a no-arg constructor provided- you must // use the all fields constructor provided /** * All fields constructor * @param accountNumber * @param accountHolderName * @param balance * @param accountType */ public Account(int accountNumber, String accountHolderName, double balance, String accountType) { this.accountNumber = accountNumber; this.accountHolderName = accountHolderName; this.balance = balance; this.accountType = accountType; } /* * Method to allow funds to be deposited * * @param double - the amount being deposited into bank */ public void deposit(double amount) { if (accountType.equals("credit card")) { // for credit card depost = payment balance = balance - amount; } else { balance = balance + amount; } } public boolean withdraw(double amount) { if (accountType.equals("credit card")) { // for credit card withdrawal adds to balance balance = balance + amount; return true; } else { if ((balance- amount) >= 0) { balance = balance - amount; return true; } else { return false; } } } /** * @return the accountHolderName */ public String getAccountHolderName() { return accountHolderName; } /** * @param accountHolderName the accountHolderName to set */ public void setAccountHolderName(String accountHolderName) { this.accountHolderName = accountHolderName; } /** * @return the accountNumber */ public int getAccountNumber() { return accountNumber; } /** * @return the balance */ public double getBalance() { return balance; } /** * @return the accountType */ public String getAccountType() { return accountType; } } 

accounts.txt file

1111 Iron Man credit card 6000 2222 Spiderman checking 300 3333 Black Widow checking 60000 4444 Black Panther credit card 5000 5555 Doctor Strange checking 200

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Relational Model A Retrospective Review And Analysis

Authors: C. J. Date

1st Edition

0201612941, 978-0201612943

More Books

Students also viewed these Databases questions

Question

3. Is it a topic that your audience will find worthwhile?

Answered: 1 week ago

Question

2. Does the topic meet the criteria specified in the assignment?

Answered: 1 week ago