Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Account.java File public class Account { // attributes protected int accountNumber; protected String accountHolderName; protected double balance; protected String accountType; // constructor // note that
Account.java File
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; } }
account.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
I have completed the first part, having trouble with the second part the DataOutputStream. I posted my code below.
Please help! Any explanation/Comments anything help to help me understand!
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 DataOutputStreamStep 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