Question
import java.util.*; public class Account { private int num; private String name; private double balance; public Account(int n, String na, double b) { num =
import java.util.*;
public class Account { private int num; private String name; private double balance; public Account(int n, String na, double b) { num = n; name = na; balance = b; } public void deposit(double add) { balance+=add; } public void withdrawal(double minus) { balance-=add; } public int getNum() { return num; } public String getName() { return name; } public double getBalance() { return balance; } public String toString() { return num + ", " + name + ", $" + balance; } }
--------_--------_---------- --_--------------_-----------
Account .java
import java.util.*; import java.io.*;
public class Lab10 { public static void main(String[] args) { ArrayList
--------_--------_---------- --_--------------_-----------
write a program that handles bank accounts. Each bank account will have an account number, name, and balance. You will support deposits and withdrawals to accounts. To make things easy for the lab, you will allow the balance to go negative.
Download the input file bank.txt. Each line has the information for a single account (account number, name, balance)
Download Lab10.zip, which contains two classes: Account and Lab10. If you are using Eclipse, create a new project with two new classes (Account and Lab10), and copy the text from the downloaded files into the new classes.
The Account class is already finished. Read through it to see what it does.
The Lab10 class is partially complete. You still need to:
Finish the find method to look up an account by number. There are comments in this method telling you what to do.
At the top of the main method, read the bank.txt file. Create a new Account object for each line in the file, and add it to the ArrayList.
Finish the deposit, withdrawal, and lookup functionality (in the switch in main).
Test your program. What happens if you give the program bad input (say, a string when it is expecting an integer)? What happens if you try to read from the file "banks.txt" (not the right name) instead?
Add try/catch blocks to your program to handle the following:
If the file the user provides does not exist, your program should print an error and exit
If the user provides bad input for the account number (i.e., not an int), amount to deposit, or amount to withdraw (not a double), your program should print an error and NOT perform that command (but keep looping and ask for the next menu option).
You may assume that there won't be any other errors in the program (such as the input file having the wrong format), but if you want to handle other problems then that's great.
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