Question

In: Computer Science

You have been hired as a programmer by a major bank. Your first project is a...

You have been hired as a programmer by a major bank. Your first project is a small banking transaction system. Each account consists of a number and a balance. The user of the program (the teller) can create a new account, as well as perform deposits, withdrawals, balance inquiries, close accounts, etc..

Initially, the account information of existing customers is to be read into an array of BankAccount objects. The private data members of the BankAccount Class will include: first name, last name, social security number, account number, account type (Checking, Savings, or CD), and account balance. The bank can handle up to MAX_NUM accounts. Use the following function to read in the data values:

public static int readAccts(BankAccount[] account, int maxAccts);

This method fills up the array (up to maxAccts) and returns the actual number of accounts read in (referred to as numAccts).

After initialization, print the initial database of accounts. Use method printAccts() described below.

The program then allows the user to select from the following menu of transactions:

Select one of the following: W - Withdrawal D - Deposit N - New account B - Balance I - Account Info X - Delete Account Q - Quit

Use the following method to produce the menu: public static void menu()

This method only displays the menu. The main program then prompts the user for a selection. You should verify that the user has typed in a valid selection (otherwise print out an error message and repeat the prompt).
Once the user has entered a selection, one of the following methods should be called to perform the specific transaction. At the end, before the user quits, the program prints the contents of the database.

public static int findAcct(BankAccount[] account, int numAccts, int reqAccount);

This method returns the index of reqAccount in the BankAccount array if the account exists, and -1 if it doesn't. It is called by all the remaining methods.

public static void withdrawal(BankAccount[] account, int num_accts);

This method prompts the user for the account number. If the account does not exist, it prints an error message. Otherwise, it asks the user for the amount of the withdrawal. If the account does not contain sufficient funds, it prints an error message and does not perform the transaction.

public static void deposit(BankAccount[] account, int num_accts);

This method prompts the user for the account number. If the account does not exist, it prints an error message. Otherwise, it asks the user for the amount of the deposit.

public static int newAcct(BankAccount[] account, int num_accts); This method prompts the user for a new account number. If the account already exists, it prints an error message. Otherwise, it adds the account to the database. The method then prompts the user to enter the new depositor’s first name, last name, social security number, the account type (Checking, Savings, or CD), and the initial opening deposit.. The method returns the new number of accounts in the database.

public static int deleteAcct(BankAccount[] account, int num_accts); This method prompts the user for an account number. If the account does not exist, or if the account exists but has a non-zero balance, it prints an error message. Otherwise, it closes and deletes the account. It returns the new number of accounts.

public static void balance(BankAccount[] account, int num_accts); This method prompts the user for an account number. If the account does not exist, it prints an error message. Otherwise, it prints the account balance.

public static void accountInfo(BankAccount[] account, int num_accts); This method prompts the user for a social security number (SSN). If no account exists for this SSN, it prints an error message. Otherwise, it prints the complete account information for all of the accounts with this SSN.

public static void printAccts(BankAccount[] account, int num_accts); This method prints a table of the complete account information for every active account.

Make sure that there is at least one depositor that has multiple accounts at the bank.

#1: Use nested classes: 1. A BankAccount consists of a Depositor, an account number, an account type, and a balance. 2. A Depositor has a Name and a social security number. 3. A Name consists of first and last names.

#2: Use a constructor to initialize the data members of a new account (including the initial accounts of the database). Hint: a constructor is a method that can be called.

Notes: 1. All output must be file directed 2. Only output must go to the file - not interactive prompts and menus. 3. No global variables are allowed 4. The program and all methods must be properly commented. 5. All data members of classes are to be private 6. Add accessor (getter) methods and mutator (setter) methods to all classes as appropriate 7. All I/O should be done outside of the BankAccount class implementation. 8. All I/O should be done within the methods of the class that contains the main() method.

Sample input:

Doe John M brown 34 lawyer 96345.87
Gold Jane F blonde 43 doctor 123456.78
Dillon Tom M black 34 teacher 87654.32

using java language pls

Solutions

Expert Solution

Code-

BankAccount class-

public class BankAccount {
  
   //attributes for Bankaccount class
   private String firstname;
   private String lastname;
   private int ssn;
   private int acno;
   private String actype;
   private int acb;
  
   //Constructor for the initialization
   public BankAccount(String firstname, String lastname, int ssn, int acno, String actype, int acb) {
       super();
       this.firstname = firstname;
       this.lastname = lastname;
       this.ssn = ssn;
       this.acno = acno;
       this.actype = actype;
       this.acb = acb;
   }
   //Getter and setter methods for the attributes
   public String getFirstname() {
       return firstname;
   }
   public void setFirstname(String firstname) {
       this.firstname = firstname;
   }
   public String getLastname() {
       return lastname;
   }
   public void setLastname(String lastname) {
       this.lastname = lastname;
   }
   public int getSsn() {
       return ssn;
   }
   public void setSsn(int ssn) {
       this.ssn = ssn;
   }
   public int getAcno() {
       return acno;
   }
   public void setAcno(int acno) {
       this.acno = acno;
   }
   public String getActype() {
       return actype;
   }
   public void setActype(String actype) {
       this.actype = actype;
   }
   public int getAcb() {
       return acb;
   }
   public void setAcb(int acb) {
       this.acb = acb;
   }

}

Banking Transaction System class- (Containing main method and all the other methods)

import java.util.*;

public class Bts {

  
   public static void main(String[] args) {
  
   //Scanner class to receive the inputs
   Scanner sc=new Scanner(System.in);
   //Variable to store the maximum value
   int MAX_NUM,i=0,num_accts;
   char ch;
   System.out.println("Enter the maximum number of bank accounts that can be inserted");
   MAX_NUM = sc.nextInt();
  
   BankAccount[] account=new BankAccount[MAX_NUM];
  
   while(sc.hasNext())
   {
       account[i].setFirstname(sc.next());
       account[i].setLastname(sc.next());
       account[i].setSsn(sc.nextInt());
       account[i].setAcno(sc.nextInt());
       account[i].setActype(sc.next());
       account[i].setAcb(sc.nextInt());
       i++;  
   }
  
   // To store the actual number of Customers (Module1)
   num_accts=readAccts(account,MAX_NUM);
   //Then printing the data (Module2)
   printAccts(account, num_accts);
  
   // Menu method
  
   //calling the menu method to validate the input
   menu();
  
   }
  
   // method to read the input of the Bank account details
   public static int readAccts(BankAccount[] account, int maxAccts)
   {
       int count=0;
      
       //iterating over the bank account object array to know the actual number of details stored
       for(BankAccount x:account)
       {
           if(x.getFirstname()==null)
               return count;
           else
               count++;
       }
       return count;
   }
  
   // method to print the database information of all the customers at the bank
   public static void printAccts(BankAccount[] account, int num_accts)
   {
       for(BankAccount i:account)
       {
           //Printing all the details of a particular Customer
           System.out.println(i.getFirstname()+" "+i.getLastname()+" "+i.getSsn()+" "+i.getAcno()+" "+i.getActype()+i.getAcb());
           System.out.println();
       }
   }
  
   // Method to display a menu
   public static void menu()
   {
       Scanner sc=new Scanner(System.in);
       char ch;
       System.out.println("Select an operation");
       ch = sc.next().charAt(0);
       if(ch=='W')
           withdrawal(account,num_accts);
       else if(ch=='D')
           deposit(account, num_accts);
       else if(ch=='N')
           newAcct(account, num_accts);
       else if(ch=='B')
           balance(account,num_accts);
       else if(ch=='I')
           accountInfo(account,num_accts);
       else if(ch=='X')
           deleteAcct(account,num_accts);
       else if(ch=='Q')
           break;
       else
           System.out.println("Enter a valid selection");  
      
   }
  
   // Withdrawal method
   public static void withdrawal(BankAccount[] account, int num_accts)
   {
       Scanner sc=new Scanner(System.in);
       int a,wd;
      
       //Receiving the A/c number from the user
       System.out.println("Enter the account number");
       a=sc.nextInt();
      
       for(BankAccount i:account)
           {
           if(a==i.getAcno())
               {
           System.out.println("Enter the withdrawal amount");
           wd=sc.nextInt();
          
           //Checking if there are funds
           if(wd>i.getAcb())
           {
               System.out.println("Insufficient funds");
               break;
           }
          
           //updating the account balance
           else
               {
               i.setAcb(i.getAcb()-wd);
               break;
               }
      
               }
           }
       //After complete search
           System.out.println("Account number doesnt exist");

   }
  
   //Deposit method
   public static void deposit(BankAccount[] account, int num_accts)
   {
       Scanner sc=new Scanner(System.in);
       int a,wd;
      
       //Receiving the A/c number from the user
       System.out.println("Enter the account number");
       a=sc.nextInt();
      
       for(BankAccount i:account)
           {
           if(a==i.getAcno())
               {
           System.out.println("Enter the deposit amount");
           wd=sc.nextInt();
          
           //Checking if there are funds
           if(wd>i.getAcb())
           {
               System.out.println("Insufficient funds");
               break;
           }
          
           //updating the account balance
           else
               {
               i.setAcb(i.getAcb()+wd);
               break;
               }
      
               }
           }
       //After complete search
           System.out.println("Account number doesnt exist");

   }
  
   //New Account updation
   public static int newAcct(BankAccount[] account, int num_accts)
   {
       Scanner sc=new Scanner(System.in);
       int a;
      
       //Receiving the A/c number from the user
       System.out.println("Enter the account number");
       a=sc.nextInt();
      
       //checking if the account exists
       for(BankAccount i:account)
           {
           if(a==i.getAcno())
           {
               System.out.println("Account already exists in the database");
               break;
           }      
   }
      
       //After the for loop, it is clear that the account doesn't exist, therefore new account will be added
       account[num_accts].setFirstname(sc.next());
       account[num_accts].setLastname(sc.next());
       account[num_accts].setSsn(sc.nextInt());
       account[num_accts].setAcno(sc.nextInt());
       account[num_accts].setActype(sc.next());
       account[num_accts].setAcb(sc.nextInt());
      
       //returning the updated number of customers
       return num_accts+1;
}
  
   //Retrieving the balance of a particular account
   public static void balance(BankAccount[] account, int num_accts)
   {
       Scanner sc=new Scanner(System.in);
   int a;
  
   //Receiving the A/c number from the user
   System.out.println("Enter the account number");
   a=sc.nextInt();
  
   //checking if the account exists
   for(BankAccount i:account)
       {
       if(a==i.getAcno())
       {
           //Printing the account balance if account number is found
           System.out.println(i.getAcb());
           break;
       }      
       }
  
   //After the for loop, if Ac number isn't found the control shifts here
   System.out.println("Account number doesnt exist");
  
   }
  
   //Retrieving the account information of a particular customer
   public static void accountInfo(BankAccount[] account, int num_accts)
   {
       Scanner sc=new Scanner(System.in);
       int a;
      
       //Receiving the A/c number from the user
       System.out.println("Enter the Social security number");
       a=sc.nextInt();
      
       //checking if the account exists and printing all the records with the existing SSN
       for(BankAccount i:account)
           {
           if(a==i.getSsn())
           {
               //Printing the account balance if account number is found
               System.out.println(i.getFirstname()+" "+i.getLastname()+" "+i.getSsn()+" "+i.getAcno()+" "+i.getActype()+i.getAcb());
               break;
           }      
           }
       }
  
   public static int deleteAcct(BankAccount[] account, int num_accts)
   {
       Scanner sc=new Scanner(System.in);
       int a;
      
       //Receiving the A/c number from the user
       System.out.println("Enter the account number");
       a=sc.nextInt();
      
       //checking if the account exists
       for(BankAccount i:account)
           {
           //Checking if the account exists and has a zero balance before deletion of the account
           if(a==i.getAcno() && i.getAcb()==0)
           {
              
               //updating the attributes of the object to null (Deleting the object)
               i.setFirstname(null);
               i.setLastname(null);
               i.setSsn(0);
               i.setAcno(0);
               i.setActype(null);
               break;
           }      
           }
      
       //updating the number of customers after deletion
       return num_accts-1;
      
   }
}


Related Solutions

As a programmer in a java project, you have been asked by your project manager to...
As a programmer in a java project, you have been asked by your project manager to describe the most efficient way to store the following assigned numbers 10,20,30,1000,200,350 for an operation which involves on calculation such as sum and average.
Suppose that you have been hired by the Environmental Protection Agency (EPA) and your first project...
Suppose that you have been hired by the Environmental Protection Agency (EPA) and your first project is answer the questions below based on the following information: MD = 3E, MACL = 10 – 2E, MACH = 60 – 2E, where MD is the marginal damage, MACL is the marginal abatement cost under the “low” scenario, MACHis the marginal abatement cost under the “high” scenario, and E represents pollution level. The agency is uncertain about the true marginal cost and believes...
Case Six   Power/Influence    You have just been hired as the project manager on a major project...
Case Six   Power/Influence    You have just been hired as the project manager on a major project that is critical to the company’s success.  Eight people from different functional specialties have been assigned to your project team.  About forty percent of their time will be devoted to the project.  They take their direction from you with respect to the project but are not under your direct authority as they continue to do other work and continue to report to their current manager.   Question: Describe...
You have been hired as an analyst for Melvin Bank and your team is working on...
You have been hired as an analyst for Melvin Bank and your team is working on an independent assessment of TWINKY, which is a firm that specializes in the production and distribution of ice and glass products in Sweden. Your assistant has provided you with the following data about the company and its industry. You analysis should include intra-company, inter-company, and industry benchmark comparisons. What can you say about the firm's overall management in terms of the following? (Be as...
You have been hired as an analyst for Bank WA and your team is working on...
You have been hired as an analyst for Bank WA and your team is working on an independent assessment of a firm that specializes in the production of freshly imported farm products from New Zealand. Your assistant has provided you with the following data about the company and its industry. Ratio 2019 2018 2017 2019- Industry Average Long-term debt 0.45 0.40 0.35 0.35 Inventory Turnover 62.65 42.42 32.25 53.25 Depreciation/Total Assets 0.25 0.014 0.018 0.015 Days’ sales in receivables 113...
You have been hired as an analyst for Bank WA and your team is working on...
You have been hired as an analyst for Bank WA and your team is working on an independent assessment of Duck Food Inc. (DF Inc.). DF Inc. is a firm that specializes in the production of freshly imported farm products from New Zealand.  Your assistant has provided you with the following data about the company and its industry. Ratio 2018 2017 2016 2018- Industry Average Long-term debt 0.45 0.40 0.35 0.35 Inventory Turnover 62.65 42.42 32.25 53.25 Depreciation/Total Assets 0.25 0.014...
You have been hired as an analyst for Bank WA and your team is working on...
You have been hired as an analyst for Bank WA and your team is working on an independent assessment of Duck Food Inc. (DF Inc.). DF Inc. is a firm that specializes in the production of freshly imported farm products from New Zealand. Your assistant has provided you with the following data about the company and its industry. Ratio 2018 2017 2016 2018- Industry Average Long-term debt 0.45 0.40 0.35 0.35 Inventory Turnover 62.65 42.42 32.25 53.25 Depreciation/Total Assets 0.25...
You have been hired as an analyst for Bank WA and your team is working on...
You have been hired as an analyst for Bank WA and your team is working on an independent assessment of Duck Food Inc. (DF Inc.). DF Inc. is a firm that specializes in the production of freshly imported farm products from New Zealand. Your assistant has provided you with the following data about the company and its industry. Ratio 2018 2017 2016 2018- Industry Average Long-term debt 0.45 0.40 0.35 0.35 Inventory Turnover 62.65 42.42 32.25 53.25 Depreciation/Total Assets 0.25...
You have been hired as an analyst for Mellon Bank and your team is working on...
You have been hired as an analyst for Mellon Bank and your team is working on an independent assessment of Daffy Duck Food Inc. (DDF Inc.) DDF Inc. is a firm that specializes in the production of freshly imported farm products from France. Your assistant has provided you with the following data for Flipper Inc and their industry. Ratio 1999 1998 1997 1999- Industry Average Long-term debt 0.45 0.40 0.35 0.35 Inventory Turnover 62.65 42.42 32.25 53.25 Depreciation/Total Assets 0.25...
You have just been hired as a manager of ABC Company.   Your first week on the...
You have just been hired as a manager of ABC Company.   Your first week on the job you are asked by upper management to review payroll. You notice the company is not paying any taxes for its employee. You ask the payroll director why there are no taxes paid and he states that all of the workers are considered independent contractors. What would you do in this case?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT