Question

In: Computer Science

Implement a simple banking system in Java. Your application should demonstrate the following. Upon running the...

Implement a simple banking system in Java. Your application should demonstrate the following. Upon running the java code, first the application should welcome the user, then ask the user to give one of the options: 1) display the balance summary, 2) withdraw money, or 3) deposit money.

Based on the options your code should perform the following operations such as 1) read the transaction details from a file and display them on the screen. 2) ask the user to enter the amount he wants to withdraw and debit the withdrawal amount from the balance amount. It has to update the file and display the transaction summary. The system should not allow an attempt to withdraw an amount greater than the balance. 3) ask the user to enter the amount he wants to deposit, credit the balance and update the file. It should display the transaction summary.

The records in the file should contain transaction number, transaction type, amount withdrawn, or amount deposited, and balance.
Example:

  1. 1 Deposit 100.0$ 1100.0$

  2. 2 Withdraw 50.0$ 1050.0$

The welcome screen should look like:

Welcome to our Banking System!
Enter your Option in a number: 1. Display balance 2. Deposit amount 3. Withdraw amount
We assume that there is an opening balance of 1000 available in the system (Assign balance=1000.0 in the beginning of the code). Also, while running first start by choosing deposit option or withdraw option.

Solutions

Expert Solution

The package structure of the project is as follows:-

The codes are as below:-

//The output of the program is:-

//banksummary.txt snapshot

//The text file of the codes are provided below:-

//BankingSystem.java

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class BankingSystem {

   public static void main(String[] args) throws IOException {
       // TODO Auto-generated method stub

       List<Record> recordList = new ArrayList<>();// list of records to be written on file
       float balance=1000;//initial opening balance
       float total_balance = balance;// total balance now
       int transaction_nos = 0; // initial no transaction is done hence 0

       System.out.println("Welcome to our Banking System!");
      
      
       //As per question the bank summary transaction details should be written in a file
       BufferedWriter out = null;
       File outf = new File("banksummary.txt"); // Creation of File Descriptor for output file
       FileWriter fw = new FileWriter(outf, true); // Creation of File Writer object
       out = new BufferedWriter(fw);
       //Initialization of FileWriter done

       loop1: while (true) {
           Scanner sc = new Scanner(System.in);

           System.out.println(
                   "Enter your Option in a number: 1. Display balance 2. Deposit amount 3. Withdraw amount 4.Exit");

           int option = sc.nextInt();

           if (option == 1) {
              
               //Displaying in console
              
               System.out.println(".....................Balance Summary............................");
               System.out.println("Initial_Balance "+balance+"$");
               for (Record record : recordList) {
                   System.out.println(record.getTransaction_number() + " " + record.getTransaction_type() + " "
                           + record.getTransaction_amount() + "$ " + record.getTotal_balance() + "$ ");
               }

           } else if (option == 2) {
               // choosing deposit
               System.out.println("Enter Deposit Amount:");
               float deposit_amt = sc.nextFloat();

               total_balance = total_balance + deposit_amt;// balance after deposit

               Record record = new Record();
               transaction_nos++;// increasing transaction number by 1
               record.setTransaction_number(transaction_nos);
               record.setTransaction_type("Deposit");
               record.setTransaction_amount(deposit_amt);
               record.setTotal_balance(total_balance);
               recordList.add(record);

               // displaying transaction summary:-
               System.out.println(record.getTransaction_number() + " " + record.getTransaction_type() + " "
                       + record.getTransaction_amount() + "$ " + record.getTotal_balance() + "$ ");

               //Writing in file
               out.append((record.getTransaction_number() + " " + record.getTransaction_type() + " "
                       + record.getTransaction_amount() + "$ " + record.getTotal_balance() + "$ \n"));

              
           } else if (option == 3) {

               System.out.println("Enter Withdrawal Amount:");
               float withdrawal_amt;
               while (true) {
                   withdrawal_amt = sc.nextFloat();

                   if (withdrawal_amt > total_balance) {
                       System.out.println(
                               "Withdrawal Amount is greater than Available Balance \nRe-Enter correct Withdrawal Amount");
                       continue;
                       // logic to prevent user from entering Withdrawal amt> Available total balance
                       // ask user to re-enter and continue the loop unless user enters correct amount
                   } else {
                       break; //correct amount entered, move to next step
                   }
               }
               total_balance = total_balance - withdrawal_amt;// balance after withdrawal

               Record record = new Record();
               transaction_nos++;// increasing transaction number by 1
               record.setTransaction_number(transaction_nos);
               record.setTransaction_type("Withdraw");
               record.setTransaction_amount(withdrawal_amt);
               record.setTotal_balance(total_balance);
               recordList.add(record);

               // displaying transaction summary:-
               System.out.println(record.getTransaction_number() + " " + record.getTransaction_type() + " "
                       + record.getTransaction_amount() + "$ " + record.getTotal_balance() + "$ ");
              
               //Writing in file
               out.append((record.getTransaction_number() + " " + record.getTransaction_type() + " "
                       + record.getTransaction_amount() + "$ " + record.getTotal_balance() + "$ \n"));

              
           } else if (option == 4) {
               break loop1;
           }
           else
           {
               continue loop1;
           }
       } // labelled while loop for displaying options
       out.close();
   }

}

//Record.java


public class Record {
  
   int transaction_number;
   String transaction_type;
   float transaction_amount;
   float total_balance;
   public int getTransaction_number() {
       return transaction_number;
   }
   public void setTransaction_number(int transaction_nos) {
       this.transaction_number = transaction_nos;
   }
   public String getTransaction_type() {
       return transaction_type;
   }
   public void setTransaction_type(String transaction_type) {
       this.transaction_type = transaction_type;
   }
   public float getTransaction_amount() {
       return transaction_amount;
   }
   public void setTransaction_amount(float transaction_amount) {
       this.transaction_amount = transaction_amount;
   }
   public float getTotal_balance() {
       return total_balance;
   }
   public void setTotal_balance(float total_balance) {
       this.total_balance = total_balance;
   }

}


Related Solutions

using Java Your mission in this exercise is to implement a very simple Java painting application....
using Java Your mission in this exercise is to implement a very simple Java painting application. Rapid Prototyping The JFrame is an example that can support the following functions: 1. Draw curves, specified by a mouse drag. 2. Draw filled rectangles or ovals, specified by a mouse drag (don't worry about dynamically drawing the shape during the drag - just draw the final shape indicated). 3. Shape selection (line, rectangle or oval) selected by a combo box OR menu. 4....
In simple Java language algorithm: Implement a static stack class of char. Your class should include...
In simple Java language algorithm: Implement a static stack class of char. Your class should include two constructors. One (no parameters) sets the size of the stack to 10. The other constructor accepts a single parameter specifying the desired size of the stack a push and pop operator an isEmpty and isFull method . Both return Booleans indicating the status of the stack Using the stack class you created in problem 1), write a static method called parse that parses...
Write a java code to demonstrate the File IO. Your code should get the following information...
Write a java code to demonstrate the File IO. Your code should get the following information from the user. • Get a file name fname for output • Get number of data (numbers) (N) you want to process from the user • Get N numbers from the users through keyboard and store them in an array • Get M (How many numbers to read from file) • (Or)You are free to use same N for M (use N for both...
Write a java code to demonstrate the File IO. Your code should get the following information...
Write a java code to demonstrate the File IO. Your code should get the following information from the user. • Get a file name fname for output • Get number of data (numbers) (N) you want to process from the user • Get N numbers from the users through keyboard and store them in an array • Get M (How many numbers to read from file) • (Or)You are free to use same N for M (use N for both...
Write a java code to demonstrate the File IO. Your code should get the following information...
Write a java code to demonstrate the File IO. Your code should get the following information from the user. • Get a file name fname for output • Get number of data (numbers) (N) you want to process from the user • Get N numbers from the users through keyboard and store them in an array • Get M (How many numbers to read from file) • (Or)You are free to use same N for M (use N for both...
Create a simple C++ application that will exhibit concurrencyconcepts. Your application should create two threads...
Create a simple C++ application that will exhibit concurrency concepts. Your application should create two threads that will act as counters. One thread should count up to 20. Once thread one reaches 20, then a second thread should be used to count down to 0. For your created code, provide a detailed analysis of appropriate concepts that could impact your application. Specifically, address:Performance issues with concurrencyVulnerabilities exhibited with use of stringsSecurity of the data types exhibited.
implement a JavaFX program to demonstrate skills and knowledge using the following: 1.General Java programming skills...
implement a JavaFX program to demonstrate skills and knowledge using the following: 1.General Java programming skills (e.g. conditionals, branching and loops) as well as object-oriented concepts) 2. Writing JavaFX applications incl. using fxml 3. • GUI Layouts (organizing UI controls) I just need some samples and explanations.
Describe the development and functions of the U.S. banking system. Your answer should include, but not...
Describe the development and functions of the U.S. banking system. Your answer should include, but not just be a catalog of, important legislation over time. Your answer should include the activities under taken by U.S. banks (as evidenced by their balance sheet and income statements).
Describe the development and functions of the U.S. banking system. Your answer should include, but not...
Describe the development and functions of the U.S. banking system. Your answer should include, but not just be a catalog of, important legislation over time. Your answer should include the activities under taken by U.S. banks (as evidenced by their balance sheet and income statements).
Create a Java application that will exhibit concurrency concepts. Your application should create two threads that will act as counters.
JAVACreate a Java application that will exhibit concurrency concepts. Your application should create two threads that will act as counters. One thread should count up to 20. Once thread one reaches 20, then a second thread should be used to count down to 0.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT