Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 9 of 9

Thread: java using textpad. Atm code not having any syntax error but runs funny

  1. #1
    Junior Member
    Join Date
    Jan 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry java using textpad. Atm code not having any syntax error but runs funny

    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


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: java using textpad. Atm code not having any syntax error but runs funny

    Can you post the output from the program that shows what it is doing? Add some comments to the output that explains what is wrong with the output.

    JOptionPane programs are very hard to debug because they take too much user interaction. I prefer a program that compiles, executes and displays ALL the results for the execution without any user input.
    To show the program's output add some println statements next to all showMessage() calls
    to print out what was shown so that you can copy that output to post on the forum.

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jan 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: java using textpad. Atm code not having any syntax error but runs funny

    [QUOTE=Norm;92383]Can you post the output from the program that shows what it is doing? Add some comments to the output that explains what is wrong with the output.

    JOptionPane programs are very hard to debug because they take too much user interaction. I prefer a program that compiles, executes and displays ALL the results for the execution without any user input.
    To show the program's output add some println statements next to all showMessage() calls
    to print out what was shown so that you can copy that output to post on the forum.

    Try running the program pls. And check ya balance three times. When ya do that jumps the the next row balance instead of sticking with the first one that ya working with. Pls try and run the program. Thanks a lot

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: java using textpad. Atm code not having any syntax error but runs funny

    Try running the program pls.
    Please post a complete list of all the answers that the program requires in the order that they are read by the program. I've written a test driver that will supply the answers to the JOPtionPane methods. It needs a String that has ALL the answers to the prompts. I am not going to answer any prompts when I test the code. The answers will be 100% supplied from the list that you provide. That will make sure I am testing it in exactly the same way you are.

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.

    Here's what the testing code I am using looks like:
       //-----------------------------------------------------------
       //  Following class for testing
       static class JOptionPane {
          static String[] retVals = {"n1","n2", "3"};  //  the responses to be returned by showInput
          static int idx = 0;  // index to above
     
          static public String showInputDialog(String msg) {
             System.out.println(msg + " val="+retVals[idx]);
             return retVals[idx++];
          }
     
          static public void showMessageDialog(Object obj1, Object obj2, String msg, int type) {
                System.out.println(msg);
          }
     
          static int INFORMATION_MESSAGE = 1;
       }   //  end JOptionPane class for testing
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Jan 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: java using textpad. Atm code not having any syntax error but runs funny

    Quote Originally Posted by Norm View Post
    Please post a complete list of all the answers that the program requires in the order that they are read by the program. I've written a test driver that will supply the answers to the JOPtionPane methods. It needs a String that has ALL the answers to the prompts. I am not going to answer any prompts when I test the code. The answers will be 100% supplied from the list that you provide. That will make sure I am testing it in exactly the same way you are.

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.

    Here's what the testing code I am using looks like:
       //-----------------------------------------------------------
       //  Following class for testing
       static class JOptionPane {
          static String[] retVals = {"n1","n2", "3"};  //  the responses to be returned by showInput
          static int idx = 0;  // index to above
     
          static public String showInputDialog(String msg) {
             System.out.println(msg + " val="+retVals[idx]);
             return retVals[idx++];
          }
     
          static public void showMessageDialog(Object obj1, Object obj2, String msg, int type) {
                System.out.println(msg);
          }
     
          static int INFORMATION_MESSAGE = 1;
       }   //  end JOptionPane class for testing
    i dont understand what you want me to try. thanks

  6. #6
    Member
    Join Date
    Sep 2012
    Posts
    128
    Thanks
    1
    Thanked 14 Times in 14 Posts

    Default Re: java using textpad. Atm code not having any syntax error but runs funny

    He wants a list of your typical input. i.e. what you type in to test it.

    --- Update ---

    There are quite a few variables that are not used. Either remove them or comment them out.

    I found some other oddities (syntax errors), like these:
    						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)))
    							 {

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: java using textpad. Atm code not having any syntax error but runs funny

    The program has many dialog boxes that ask for user input. To test the program and have it execute the same way that it does when you test it, I need a complete list of all the responses that you type into the dialog boxes in the same order that you type them in.

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  8. #8
    Junior Member
    Join Date
    Jan 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: java using textpad. Atm code not having any syntax error but runs funny

    download the input file at the bottom if my question called ATM.txt. the first column is the account number and the second column is the password and the third column is the amount of the account. i appreciate the help and effort yall

  9. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: java using textpad. Atm code not having any syntax error but runs funny

    What do you need the contents of the ATM.txt file for? Isn't that file read by the program?

    To test the program I need a complete list of all the responses that you type into the dialog boxes in the same order that you type them in.

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. MySQL Syntax error in Java prepared statement
    By kc120us in forum JDBC & Databases
    Replies: 4
    Last Post: March 22nd, 2012, 11:31 AM
  2. no error when compiled but when the program runs .. help this !!!
    By izzahmed in forum What's Wrong With My Code?
    Replies: 5
    Last Post: November 8th, 2011, 08:55 AM
  3. textpad & java
    By dvsumosize in forum Java IDEs
    Replies: 3
    Last Post: February 3rd, 2010, 09:27 AM
  4. Robo Code - The funny Java Programming Game
    By Freaky Chris in forum The Cafe
    Replies: 20
    Last Post: October 8th, 2009, 03:42 PM
  5. Replies: 4
    Last Post: April 21st, 2009, 09:37 AM

Tags for this Thread