Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Could you please help with this programming assignment: The Lab 10 java file contains the following code, but I need the comment sections filled in

Could you please help with this programming assignment:

image text in transcribed

The Lab 10 java file contains the following code, but I need the comment sections filled in accordingly:

import java.util.*;

import java.io.*;

public class Lab10 {

public static void main(String[] args) {

ArrayList list = new ArrayList();

Scanner s = new Scanner(System.in);

System.out.print("Enter the name of the input file: ");

String filename = s.nextLine();

//YOU DO THIS:

//Open the file in the filename variable

//Parse each line, create an Account object, and add it to the list

char option;

do {

System.out.print("Enter (p)rint, (d)eposit, (w)ithdrawal, (l)ookup, or (q)uit: ");

option = (s.nextLine()).charAt(0);

switch (option) {

case 'p':

System.out.print("Enter acount number: ");

int num = Integer.parseInt(s.nextLine());

Account a = find(list, num);

System.out.println(a);

break;

case 'd':

System.out.print("Enter account number: ");

num = Integer.parseInt(s.nextLine());

//YOU DO THIS:

//Call find to get the account with that number

System.out.print("Enter deposit amount: ");

double dep = Double.parseDouble(s.nextLine());

//YOU DO THIS:

//Call deposit on the account you got back to deposit dep

break;

case 'w':

System.out.print("Enter account number: ");

num = Integer.parseInt(s.nextLine());

//YOU DO THIS:

//Call find to get the account with that number

System.out.print("Enter withdrawal amount: ");

double with = Double.parseDouble(s.nextLine());

//YOU DO THIS:

//Call deposit on the account you got back to withdraw with

break;

case 'l':

System.out.print("Enter name: ");

String name = s.nextLine();

//YOU DO THIS:

//Loop through each account, calling get to get each one (or using an Iterator)

//for each account, see if its name matches the name from the user

//if so, print the number for that account

break;

}

} while (option != 'q');

}

public static Account find(ArrayList accounts, int num) {

//YOU DO THIS

//loop through accounts, calling get to get each account (or using an Iterator)

//for each account, see if its number matches num

//if so, return that account

//leave this at the very end of the method in case the account isn't found

return null;

}

}

Same for the Account.java file:

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;

}

}

Also, here's a screenshot of the bank.txt file:

image text in transcribed

You will 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 wll allow the balance to go negative. Download the input file bank.bxt. Each line has the information for a single account(account number, name, balance Download Lab10zip, which contains two classes: Account and Lab10. If you are using Eclipse, create a new project with two new classes Account and Lab0), 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 o At the top of the main method, read the bank.tot 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.trt" (not the right name instead? Add try/catch blocks to your program to handle the following: f 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 numberi.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). ou may assume that there wont be any other errors in the program (such as the input ile 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

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

Transactions On Large Scale Data And Knowledge Centered Systems X Special Issue On Database And Expert Systems Applications Lncs 8220

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Stephen W. Liddle ,Klaus-Dieter Schewe ,Xiaofang Zhou

2013th Edition

3642412203, 978-3642412202

More Books

Students also viewed these Databases questions

Question

6. Identify seven types of hidden histories.

Answered: 1 week ago

Question

What is human nature?

Answered: 1 week ago