my project is due on monday. its about an ATM. i shows no errors but it runs wierd. when i chek my balance it shows me the first balance and when i run it again it jumps to the next balance instead of sticking with the first one and it doesnt accept the second and third row of username and passwprd. you will understand it better when you run it. p,ls help me i need this before monday.ill attach the file and input file. the code is below:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.event.ActionEvent;
import java.util.*;
import java.lang.String;
import java.io.*;
import javax.swing.JOptionPane.*;
public class CNEATM extends JFrame
{
private JButton aButton;
private JButton pButton;
private JButton wButton;
private JButton dButton;
private JButton qButton;
private JButton welButton;
private QuitButtonHandler qHandler;
private WelcomeButtonHandler welHandler;
private static final int WIDTH = 500;
private static final int HEIGHT = 200;
public CNEATM()
{
qButton = new JButton(" QUIT ");
qHandler = new QuitButtonHandler();
qButton.addActionListener(qHandler);
welButton = new JButton(" Welcome.. Lets get started ");
welHandler = new WelcomeButtonHandler();
welButton.addActionListener(welHandler);
//My Title
setTitle("ATM");
//Get the container
Container pane = getContentPane();
//Set the layout
pane.setLayout(new GridLayout(5,1));
//Place all items created
pane.add(qButton);
pane.add(welButton);
//set the size of the window and display it
setSize(WIDTH,HEIGHT);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
private class QuitButtonHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
}
public static void main(String[] args)
{
CNEATM rectObject = new CNEATM();
}
private class WelcomeButtonHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
try
{
Scanner inFile = new Scanner (new FileReader("ATM.txt"));
String name;
String name2, Bal = "Your Balance";
name = JOptionPane.showInputDialog("enter the account number ");
name2 = JOptionPane.showInputDialog("enter the pin number ");
String selection = " ";
String iF1, iF2, iF3 ,Password = "Wrong Password or Account Number.... Goodbye" ;;
while(inFile.hasNext())
{
iF1 = inFile.next();
System.out.Println(+ iF1 +iF2 +iF3);
iF2 = inFile.next();
iF3 = inFile.next();
System.out.Println(+ iF1 +iF2 +iF3);
if((iF1.equals(name)) && (iF2.equals(name2)))
{
selection = JOptionPane.showInputDialog(" [1] Check Balance \n [2] Withdrawal \n [3] Deposit \n [4] Exit ");
}
if (Integer.parseInt(selection) == 1)
{
String selection1;
String bala = " Amount " +iF3;
JOptionPane.showMessageDialog(null,Bal, "You have selected Balance.\n", JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog(null, bala,"\t-- Your Current Balance ", JOptionPane.INFORMATION_MESSAGE);
selection1 = JOptionPane.showInputDialog("Return to main menu? \n [1] for YES \n [2] for NO");
if (Integer.parseInt(selection1)==1)
selection = JOptionPane.showInputDialog(" [1] Check Balance \n [2] Withdrawal \n [3] Deposit \n [4] Exit ");
else
System.exit(0);
}
if (Integer.parseInt(selection)== 2 )
{
String withdrawSelection, Back;
String with = "Withdrawal", withdr = "withdrawal", withdra = "withdrawal";
int Pay = 0;
int currentBal;
withdrawSelection = JOptionPane.showInputDialog("Enter amount in multiple of 20");
if (Integer.parseInt(withdrawSelection) % 20 == 0 && Integer.parseInt(selection) < 10000)
Pay += Integer.parseInt(withdrawSelection);
currentBal = Integer.parseInt(iF3) - Pay;
JOptionPane.showMessageDialog(null, with, "Please take your funds.", JOptionPane.INFORMATION_MESSAGE);
Back = JOptionPane.showInputDialog("Return to main menu? \n [1] for YES \n [2] for exit");
if (Integer.parseInt(Back)==1)
selection = JOptionPane.showInputDialog(" [1] Check Balance \n [2] Withdrawal \n [3] Deposit \n [4] Exit ");
else
System.exit(0);
}
if (Integer.parseInt(selection)== 3 )
{
String addSelection, Deposit = "Deposit made", Money, backe;
int Paye = 0;
Money = JOptionPane.showInputDialog (" Whats the Amt");
if (Integer.parseInt(Money) % 20 == 0 && Integer.parseInt(selection) < 10000)
Paye += Integer.parseInt(Money);
int depositFunds, currentBal;
currentBal = Integer.parseInt(iF3) + Paye;
JOptionPane.showMessageDialog(null, Deposit,"Thank you.", JOptionPane.INFORMATION_MESSAGE);
backe = JOptionPane.showInputDialog("Return to main menu? \n [1] for YES \n [2] for NO");
if (Integer.parseInt(backe)==1)
selection = JOptionPane.showInputDialog(" [1] Check Balance \n [2] Withdrawal \n [3] Deposit \n [4] Exit ");
else
System.exit(0);
}
if (Integer.parseInt(selection)== 4 )
{
System.exit(0);
} ;
}
inFile.close();
JOptionPane.showMessageDialog(null,Password , "Enter Password and Acc Number", JOptionPane.INFORMATION_MESSAGE);
}
catch(FileNotFoundException FNFE){JOptionPane.showInputDialog("Invalid file");}
}
}
}
ATM.txtCNEATM.txt