In: Computer Science
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.
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