Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a function processAccount() that takes one argument, the name of a file Th

ID: 3661717 • Letter: W

Question

Write a function processAccount() that takes one argument, the name of a file The first line of the file is a number, which indicates the initial balance for a bank account. The remaining lines consist of a single character followed by a space followed by a number. The character will be one of 'd', 'D', 'w', or 'W', indicating that the amount that follows is either a withdrawal ('w' or 'W') or a deposit ('d' or 'D'). The function will create a new BankAccount object and then process each line of the file by calling the appropriate method of the BankAccount object. As it processes each line, it will print the information about the transaction being processed. The first line will be a call to the set() method and the remaining lines will be calls either to the deposit() or withdraw() method. Once the file has been processed, the function will print the final account balance and return the BankAccount object.

>>> processAccount('acct1.txt')

BankAccount(605.5500000000001)

>>> b = processAccount('acct1.txt')

>>> b

BankAccount(605.5500000000001)

>>> b.balance()

605.5500000000001

>>>

>>> b = processAccount('acct2.txt')

>>> b

BankAccount(46.94)

>>> b.balance()

46.94

>>>

>>> b = processAccount('acct3.txt')

>>> b

BankAccount(216.64)

>>> b.balance()

216.64

>>>

Explanation / Answer

package Cryptography;

import java.io.*;
import java.util.*;

class BankAccount
{
    private int balance;

    /**
     * Constructor for objects of class BankAccount
     */
    public BankAccount()
    {
       
        balance = 0;
    }

    public void showBalance()
    {
        System.out.println("Balance is "+balance);
    }
   
    public void deposit(int amount)
    {
        balance=balance+amount;
    }
    public void withdraw(int amount)
    {
        balance=balance-amount;
    }
    public static void processAccount(String fname) throws IOException
    {
        BankAccount b1=new BankAccount();
        Scanner scanner = new Scanner(new File(fname));
        int i = 0;
        while(scanner.hasNextInt())
        {
            b1.balance = scanner.nextInt();
            System.out.println(b1.balance);
        }
    }
}
    public class BankAccountTest
    {
       
        public static void main(String args[])throws IOException
        {
            String f1="acct1.txt";
            BankAccount b1= new BankAccount();
            b1.processAccount(f1);
        }
    }
   

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote