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 Deposit 100.0$ 1100.0$

2 Withdraw 50.0$ 1050.0$

The welcome screen should look like:

Welcome to CIS-2348 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

Source code:

import java.util.Scanner;
import java.io.*;
class Account
{
   private String ano;
   private String name;
   int balance=1000;

   Scanner S = new Scanner(System.in);

   void show()
   {
       try{  
            FileInputStream fin=new FileInputStream("Account.txt");    
           BufferedInputStream bin=new BufferedInputStream(fin);  
           int i;
           String k="";  
           while((i=bin.read())!=-1){  
               k = k+(char) i ;
              
           }  
           System.out.println(k);
           bin.close();
            fin.close();
           
          }catch(Exception e){System.out.println(e);}
   }

   void deposit(int a)
   {
       int amt;
       System.out.print("Enter ammount to deposit ");
       amt=S.nextInt();
       balance=balance+amt;
       try{  
             FileOutputStream file=new FileOutputStream("Account.txt");  
             String s=a+" Deposit "+amt+" "+balance;  
             byte b[]=s.getBytes();//converting string into byte array
             file.write(b);
           
            FileInputStream fin=new FileInputStream("Account.txt");    
           BufferedInputStream bin=new BufferedInputStream(fin);  
           int i;
           String k="";  
           while((i=bin.read())!=-1){  
               k = k+(char) i ;
              
           }
           k= k+s;
           byte v[] = k.getBytes();  
             file.close();  
             System.out.println("Successfully completed");
             System.out.println();
            }
         catch(Exception e){
           System.out.println(e);
           }
      
   }

   void withdraw(int a)
   {
       int amt;
       System.out.print("Enter ammount to withdraw ");
       amt=S.nextInt();
       if(balance>=amt)
       {
           balance=balance-amt;
           try{  
             FileOutputStream file=new FileOutputStream("Account.txt");  
             String s=a+" Withdraw "+amt+" "+balance;  
             byte b[]=s.getBytes();//strings into bytes  
             file.write(b);  
             file.close();
             System.out.println("Successfully completed");
             System.out.println();    
            }
            catch(Exception e){
               System.out.println(e);
           }
       }
       else
       {
           System.out.println("Not enough balance");
       }
   }
}

public class Banks extends Account
{
   public static void main(String arg[])
   {
       Scanner B=new Scanner(System.in);
       Account a = new Account();
       int c;
       c=0;
       System.out.print("Welcome to CIS-2348 Banking System! \n");
       int ch;
       do
       {
           System.out.println("Main Menu   1.Display balance summary \t 2.Deposit\t 3.Withdrawal\t 4.Exit");
           System.out.print("Your option : ");
           ch=B.nextInt();
           switch(ch)
           {
               case 1:
                   a.show();
                   System.out.println();
                   break;

               case 2:
                   c=c+1;
                   a.deposit(c);
                   break;

               case 3:
                    c=c+1;
                   a.withdraw(c);
                   break;

               case 4:
                   System.out.println("Thank you and please visit again ");
                   break;
           }
       }
       while(ch!=4);
   }
}

File


Related Solutions

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...
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...
Language: Java(Netbeans) Implement a simple calculator.
Language: Java(Netbeans) Implement a simple calculator.
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.
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).
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT