I'm making an ATM machine program for my case study. How can I return to the first output which is the main menu (the one with balance inquiry etc.) after the user pressed cancel for example (I didn't code it yet).
From comment: "how can i display the same window (which is the main menu) if for example the user finished withdrawing."
import javax.swing.JOptionPane;
import java.util.Scanner;
public class casestudy
{
public static void main (String Args [])
{
Scanner sc=new Scanner (System.in);
String acct[]={"0123-4567-8901", "2345-6789-0123", "3456-7890-1234","4567-8901-2345", "5678-9012-3456"};
String name[]={"Dina Balle", "Mally Gaya", "Toto Lee", "Mina Mahal", "Cory Pot"};
int bal[]={5000, 0, 10000, 2500, 10000};
int pinarr []={0000, 1111, 2222, 3333, 4444, 5555};
int wdamount=0;
int depamount =0;
int pinattempt=0;
int wrongall=0;
boolean correct = false;
boolean wrong = false;
String g=JOptionPane.showInputDialog ("WELCOME TO FILIPINAS BANKING CORPORATION!\n\nPress [C] if you are a CUSTOMER, [A] if you are an ADMINISTRATOR: ");
char level = g.charAt(0);
switch (level)
{
case 'A':
case 'a': JOptionPane.showMessageDialog(null, "HEHE");break;
default : JOptionPane.showMessageDialog(null, "INVALID CODE!"); System.exit(0); break;
case 'C':
case 'c':
{
String a=JOptionPane.showInputDialog ("FILIPINAS BANKING CORPORATION\n===========================================\nPress [S] to START TRANSACTION and [Q] to QUIT: ");
char choice = a.charAt(0);
switch (choice)
{
case 'Q':
case 'q': JOptionPane.showMessageDialog(null,"The program will now exit"); System.exit(0); break;
default : JOptionPane.showMessageDialog(null,"INVALID SELECTION!"); System.exit(0); break;
case 'S':
case 's':
JOptionPane.showMessageDialog (null, "====================FBC====================\n\nFILIPINAS BANKING CORPORATION\n\n\n\t\t\tSTART TRANSACTION!");
while ((pinattempt!=3)&&(correct=true))
{
int pin=Integer.parseInt (JOptionPane.showInputDialog ("Enter your PIN: "));
switch (pin)
{
case 1111:
{
pinattempt=3; correct=true;
String b=JOptionPane.showInputDialog("====================FBC====================\n\nFILIPINAS BANKING CORPORATION\n\t\t\tSELECT TYPE OF TRANSACTION\n\t\t[B] - BALANCE INQUIRY\n\t\t[W] - WITHDRAWAL\n\t\t[D] - DEPOSIT \n\t\t[C] - CANCEL");
char pick=b.charAt(0);
switch (pick)
{
case 'B':
case 'b': JOptionPane.showMessageDialog(null, "Account #: " +acct [0]+"\n"+"Account Name: " +name [0]+"\n"+"Balance: "+bal[0],"Balance Inquiry",JOptionPane.INFORMATION_MESSAGE);System.exit(0); break;
case 'W':
case 'w':
String q =JOptionPane.showInputDialog("Enter Amount to be WITHDRAWN: ");
wdamount = Integer.parseInt(q);
if ((wdamount<100)||(wdamount%100!=0))
{
JOptionPane.showMessageDialog(null, "Invalid Amount!");System.exit(0);
}
JOptionPane.showMessageDialog(null,"Account Name: " +name [0]+"\n"+"The current BALANCE is now: " +(bal[0]-wdamount),"Balance Inquiry",JOptionPane.INFORMATION_MESSAGE); break;
case 'D':
case 'd':
String l = JOptionPane.showInputDialog("Enter amount to be DEPOSITED: ");
depamount = Integer.parseInt(l);
if ((depamount<100)||(depamount%100!=0))
{
JOptionPane.showMessageDialog(null, "Invalid Amount!");System.exit(0);
}
JOptionPane.showMessageDialog(null,"Account Name: " +name [0]+"\n"+"The current BALANCE is now: " +(bal[0]+depamount),"Balance Inquiry",JOptionPane.INFORMATION_MESSAGE);
break;
}
}break;
case 2222:
{
pinattempt=3; correct=true;
String c=JOptionPane.showInputDialog("====================FBC====================\n\nFILIPINAS BANKING CORPORATION\n\t\t\tSELECT TYPE OF TRANSACTION\n\t\t[B] - BALANCE INQUIRY\n\t\t[W] - WITHDRAWAL\n\t\t[D] - DEPOSIT \n\t\t[C] - CANCEL");
char pick=c.charAt(0);
switch (pick)
{
case 'B':
case 'b': JOptionPane.showMessageDialog(null, "Account #: " +acct [1]+"\n"+"Account Name: " +name [1]+"\n"+"Balance: "+bal[1],"Balance Inquiry",JOptionPane.INFORMATION_MESSAGE);System.exit(0); break;
case 'W':
case 'w':
if (bal[1]<=0)
{
JOptionPane.showMessageDialog(null, "You cannot withdraw because you have "+bal[1]+" balance.");
System.exit(0);
}
String q =JOptionPane.showInputDialog("Enter Amount to be WITHDRAWN: ");
wdamount = Integer.parseInt(q);
if ((wdamount<100)||(wdamount%100!=0))
{
JOptionPane.showMessageDialog(null, "Invalid Amount!");System.exit(0);
}
}
}break;
case 3333:
{
pinattempt=3; correct=true;
String d=JOptionPane.showInputDialog("====================FBC====================\n\nFILIPINAS BANKING CORPORATION\n\t\t\tSELECT TYPE OF TRANSACTION\n\t\t[B] - BALANCE INQUIRY\n\t\t[W] - WITHDRAWAL\n\t\t[D] - DEPOSIT \n\t\t[C] - CANCEL");
char pick=d.charAt(0);
switch (pick)
{
case 'B':
case 'b':
JOptionPane.showMessageDialog(null, "Account #: " +acct [2]+"\n"+"Account Name: " +name [2]+"\n"+"Balance: "+bal[2],"Balance Inquiry",JOptionPane.INFORMATION_MESSAGE);System.exit(0); break;
case 'W':
case 'w':
String q =JOptionPane.showInputDialog("Enter Amount to be WITHDRAWN: ");
wdamount = Integer.parseInt(q);
if ((wdamount<100)||(wdamount%100!=0))
{
JOptionPane.showMessageDialog(null, "Invalid Amount!");System.exit(0);
}
JOptionPane.showMessageDialog(null,"Account Name: " +name [2]+"\n"+"The current BALANCE is now: " +(bal[2]-wdamount),"Balance Inquiry",JOptionPane.INFORMATION_MESSAGE); break;
case 'D':
case 'd':
String l = JOptionPane.showInputDialog("Enter amount to be DEPOSITED: ");
depamount = Integer.parseInt(l);
if ((depamount<100)||(depamount%100!=0))
{
JOptionPane.showMessageDialog(null, "Invalid Amount!");System.exit(0);
}
JOptionPane.showMessageDialog(null,"Account Name: " +name [2]+"\n"+"The current BALANCE is now: " +(bal[2]+depamount),"Balance Inquiry",JOptionPane.INFORMATION_MESSAGE);
break;
}
}break;
case 4444:
{
pinattempt=3; correct=true;
String e=JOptionPane.showInputDialog("====================FBC====================\n\nFILIPINAS BANKING CORPORATION\n\t\t\tSELECT TYPE OF TRANSACTION\n\t\t[B] - BALANCE INQUIRY\n\t\t[W] - WITHDRAWAL\n\t\t[D] - DEPOSIT \n\t\t[C] - CANCEL");
char pick=e.charAt(0);
switch (pick)
{
case 'B':
case 'b':
JOptionPane.showMessageDialog(null, "Account #: " +acct [3]+"\n"+"Account Name: " +name [3]+"\n"+"Balance: "+bal[3],"Balance Inquiry",JOptionPane.INFORMATION_MESSAGE);System.exit(0); break;
case 'W':
case 'w':
String q =JOptionPane.showInputDialog("Enter Amount to be WITHDRAWN: ");
wdamount = Integer.parseInt(q);
if ((wdamount<100)||(wdamount%100!=0))
{
JOptionPane.showMessageDialog(null, "Invalid Amount!");System.exit(0);
}
JOptionPane.showMessageDialog(null,"Account Name: " +name [3]+"\n"+"The current BALANCE is now: " +(bal[3]-wdamount),"Balance Inquiry",JOptionPane.INFORMATION_MESSAGE); break;
case 'D':
case 'd':
String l = JOptionPane.showInputDialog("Enter amount to be DEPOSITED: ");
depamount = Integer.parseInt(l);
if ((depamount<100)||(depamount%100!=0))
{
JOptionPane.showMessageDialog(null, "Invalid Amount!");System.exit(0);
}
JOptionPane.showMessageDialog(null,"Account Name: " +name [3]+"\n"+"The current BALANCE is now: " +(bal[3]+depamount),"Balance Inquiry",JOptionPane.INFORMATION_MESSAGE);
break;
}
}break;
case 5555:
{
pinattempt=3; correct=true;
String f=JOptionPane.showInputDialog("====================FBC====================\n\nFILIPINAS BANKING CORPORATION\n\t\t\tSELECT TYPE OF TRANSACTION\n\t\t[B] - BALANCE INQUIRY\n\t\t[W] - WITHDRAWAL\n\t\t[D] - DEPOSIT \n\t\t[C] - CANCEL");
char pick=f.charAt(0);
switch (pick)
{
case 'B':
case 'b': JOptionPane.showMessageDialog(null, "Account #: " +acct [4]+"\n"+"Account Name: " +name [4]+"\n"+"Balance: "+bal[4],"Balance Inquiry",JOptionPane.INFORMATION_MESSAGE); break;
case 'W':
case 'w':
String q =JOptionPane.showInputDialog("Enter Amount to be WITHDRAWN: ");
wdamount = Integer.parseInt(q);
if ((wdamount<100)||(wdamount%100!=0))
{
JOptionPane.showMessageDialog(null, "Invalid Amount!");System.exit(0);
}
JOptionPane.showMessageDialog(null,"Account Name: " +name [4]+"\n"+"The current BALANCE is now: " +(bal[4]-wdamount),"Balance Inquiry",JOptionPane.INFORMATION_MESSAGE); break;
case 'D':
case 'd':
String l = JOptionPane.showInputDialog("Enter amount to be DEPOSITED: ");
depamount = Integer.parseInt(l);
if ((depamount<100)||(depamount%100!=0))
{
JOptionPane.showMessageDialog(null, "Invalid Amount!");System.exit(0);
}
JOptionPane.showMessageDialog(null,"Account Name: " +name [4]+"\n"+"The current BALANCE is now: " +(bal[4]+depamount),"Balance Inquiry",JOptionPane.INFORMATION_MESSAGE);
break;
}
}break;
default: //pin validation
{
pinattempt++; wrongall++; wrong = false;
if ((wrongall==3)&&(wrong==false))
{
JOptionPane.showMessageDialog(null,"CAPTURED CARD... PLEASE CALL 143-44"); System.exit(0);
}
} //pin validation up to here
}
}
}
}
}
}
}