Hello guys, I am new to this website. It's nice to see these friendly people, anyways....

I have been trying to learn Java for a little bit now, I know the basics and some of the advanced things. But I came across a problem that is intriguing me so much. The problem was to create an ATM, I was provided with the ATM_UI class, a list of accounts called...accounts.txt, ATM class and another class.

The information you are prompted to input are Number, "PIN", if those 2 match then you can withdraw or deposit money.

But what I am tasked with is completing the program, it is supposed to read the accounts.txt file then analyze it. I will not post the 4 classes unless someone is willing to help me out....It would be muchly appreciated!

Nisaac

If you post your files, people will be more willing to help because it gives them time to look at your logic and help you understand which steps to take to complete your project.

//Heres the ATM class
import java.util.*;
import hsa.*;
public class ATM
{

    public static final int ENTER_ACC = 0; //Enter Account No. state
    public static final int ENTER_PIN = 1; //Enter PIN state
    public static final int ENTER_TRANSACT = 2; //Enter transaction state

    private ATM_UI ui;
    private int state;
    private TextInputFile reader = new TextInputFile ("accounts.txt");
    private TextOutputFile writer = new TextOutputFile ();
    private int account;
    private int pin;
    private int transact;
    private int balance;
    public ATM (ATM_UI atm_ui)
    {
    state = ENTER_ACC; //assign the initial state to the Account state
    ui = atm_ui; //assign the passed userinterface to our instance variable.
    }


    public int getState ()
    {
    return state;
    }


    /**     The method to write the updated account.txt file when the
        user clicks the "close" button
    */
    public void writeFile ()
    {

    }


    /**     Button ACOOUNT was pushed in the userinterface and your logic must determine what
     *      to do about it.
     */
    public void AButtonClicked ()
    {
    if (state == ENTER_ACC)
    {
        account = ui.getKeyPadInt();
    }
    if (state == ENTER_PIN)
    {
    }
    if (state == ENTER_TRANSACT)
    {
    }
    }


    /**     Button PIN was pushed in the userinterface and your logic must determine what
     *      to do about it.
     */
    public void PButtonClicked ()
    {
    if (state == ENTER_ACC)
    {
    }
    if (state == ENTER_PIN)
    {
        pin = ui.getKeyPadInt();
    }
    if (state == ENTER_TRANSACT )
    {
    }
    }


    /**     Button WITHDRAWAL was pushed in the userinterface and your logic must determine what
     *      to do about it.
     */
    public void WButtonClicked ()
    {

    }


    /**     Button DEPOSIT was pushed in the userinterface and your logic must determine what
     *      to do about it.
     */
    public void DButtonClicked ()
    {

    }


    /**     Button QUIT was pushed in the userinterface and your logic must determine what
     *      to do about it.
     */
    public void QButtonClicked ()
    {

    }
}
//here is the User Interface bit
/**     this class is the userinterface for our simulation. Interaction between the ATM (Rules)
 *      class and this class will occur. But, this class will not interact any class other 
 *      than ATM and KeyPad. 
 */ 
public class ATM_UI extends JFrame{

    //reference to the mechanics of the ATM
    private ATM atm; 

    //the buttons to be used in the frame
    private Button aButton;
    private Button pButton;
    private Button wButton;
    private Button dButton;
    private Button qButton;

    //an instance of our keypad class
    private KeyPad pad;

    //an instance of the textarea
    private TextArea display;


    /**     Constructor to create the user interface. 
     */
    public ATM_UI(){

        final int FRAME_WIDTH = 500;
        final int FRAME_HEIGHT=200;

        this.setSize(FRAME_WIDTH, FRAME_HEIGHT);//set the size of the frame

        addWindowListener(new WindowCloser());

        //create the atm which controls the rules of the program
        atm = new ATM(this);


        //create components. You will not have to worry about the items below.
        //but you will need to know the methods below. 
        pad = new KeyPad();                            
        display = new TextArea(4, 30);

        aButton = new Button("  ACCOUNT ");
        aButton.addActionListener(new AButtonListener());

        pButton = new Button("    PIN   ");
        pButton.addActionListener(new PButtonListener());

        wButton = new Button("WITHDRAWAL");
        wButton.addActionListener(new WButtonListener());

        dButton = new Button("  DEPOSIT ");
        dButton.addActionListener(new DButtonListener());

        qButton = new Button("   QUIT   ");
        qButton.addActionListener(new QButtonListener());

        //add components to content pane
        Panel buttonPanel = new Panel();
        buttonPanel.setLayout(new GridLayout(5,1));
        buttonPanel.add(aButton);
        buttonPanel.add(pButton);
        buttonPanel.add(wButton);
        buttonPanel.add(dButton);
        buttonPanel.add(qButton);

        Container contentPane = getContentPane();
        contentPane.setLayout(new FlowLayout());
        contentPane.add(pad);
        contentPane.add(display);
        contentPane.add(buttonPanel);

        this.setResizable(false);
        this.setVisible(true);
        setDisplayMsg();
    }


    /**     gets the integer value from the keypad display
     *      @return the value in the display
     */     
     public int getKeyPadInt(){
        return (int)pad.getValue();
     }
     /**    gets the double value from the keypad display
     */
     public double getKeyPadDouble(){
        return pad.getValue();
     }

    /**     the user interface will clear the diplay so that nothing is in the text area
     */
     public void clearDisplay(){
        pad.clear();
     }

     /**    The user interface will display instructions for interacting with the atm
        simulation.
     */
     private String displayMsg(){
        int state = atm.getState();
        if (state==ATM.ENTER_ACC){
            return "Enter your account number\n";
        }
        else if (state == ATM.ENTER_PIN){
            return "Enter your PIN\n";
        }
        else if (state == ATM.ENTER_TRANSACT){
            return "Enter an amount and press a transaction.\nPress quit to end\n"; 
        }
        else{
            return "Error\n";
        }
     }

     /**    Tell the user interface to display the state message plus any additional message
        supplied by the ATM
     */
     public void setDisplayMsg(String s){
        display.setText(displayMsg() + s);
     }

     /**    Tell the user interface to display the default state message
     */
     public void setDisplayMsg(){
        display.setText(displayMsg());
    }


    /**     sets the text area to display the options when in the transaction state. 
     *      This method is not completed....we will complete this as we create the ATM class
     */

    /**     The code below is needed to tell the ATM Class that a button has been pushed
     *      you will not need to modify this code below. You will not need to understand 
     *      how it works.....just that it is needed is good enough
     */
     private class AButtonListener implements ActionListener{
        public void actionPerformed(ActionEvent event){
            atm.AButtonClicked();        
        }
     }

     private class PButtonListener implements ActionListener{
        public void actionPerformed(ActionEvent event){
            atm.PButtonClicked();


        }
     }

     private class WButtonListener implements ActionListener{
        public void actionPerformed(ActionEvent event){
            atm.WButtonClicked();
        }
     }

     private class DButtonListener implements ActionListener{
        public void actionPerformed(ActionEvent event){
            atm.DButtonClicked();
        }
     }

     private class QButtonListener implements ActionListener{
        public void actionPerformed(ActionEvent event){
            atm.QButtonClicked();
        }
     }

     private class WindowCloser extends WindowAdapter{
        public void windowClosing(WindowEvent event){
            atm.writeFile();
            System.exit(0);
        }
     }      
}
import java.awt.*;
import java.awt.event.*;

/**     a component that lets the user enter a number, using a button pad labeled with digits
 */
public class KeyPad extends Panel
{

    private Panel buttonPanel;//panel containing the buttons
    private TextField display;//field to display the number entered

    public KeyPad ()
    {
    setLayout (new BorderLayout ());

    //add display field
    display = new TextField ();
    display.setEditable(false);
    display.setEnabled(false);
    display.setBackground(Color.WHITE);
    add (display, BorderLayout.NORTH);

    //make button panel

    buttonPanel = new Panel ();
    buttonPanel.setLayout (new GridLayout (4, 3));

    //add digit buttons
    ActionListener listener = new DigitButtonListener ();

    addButton ("7", listener);
    addButton ("8", listener);
    addButton ("9", listener);
    addButton ("4", listener);
    addButton ("5", listener);
    addButton ("6", listener);
    addButton ("1", listener);
    addButton ("2", listener);
    addButton ("3", listener);
    addButton ("0", listener);
    addButton (".", listener);
    addButton ("C", listener);

    add (buttonPanel, BorderLayout.CENTER);


    }


    /**     gets the value that the user entered
     *      @return the value in the text field of the keypad
     */
    public double getValue ()
    {
    return Double.parseDouble (display.getText ());
    }


    /**     Clears the display */

    public void clear ()
    {
    display.setText ("0");
    }


    /*************************************************************************
     *     You will not need to worry about the code below here
     */

    /**     adds a button to the panel
     *      @param label the button label
     *      @param listener the button listener
     */
    private void addButton (String label, ActionListener listener)
    {
    Button button = new Button (label);
    buttonPanel.add (button);
    button.addActionListener (listener);

    }


    private class DigitButtonListener implements ActionListener
    {
    public void actionPerformed (ActionEvent event)
    {

        Button source = (Button) event.getSource ();
        String label = source.getLabel ();
        String disp = display.getText();
        int decPos = disp.indexOf (".");
        if (label.equals("C")){
        display.setText("0");
        }
        else if (label.equals ("."))
        {
        if (decPos == -1){
            display.setText(disp+label);
        }
        }
        else
        {
        if (disp.length() == 1){
            if (disp.equals("0")){
            display.setText(label);
            }
            else{
            display.setText(disp + label);
            }
        }
        else if (decPos == -1 || disp.length() - decPos < 3){
            display.setText(disp+label);
        }
        }
    }
    }
}

//amount of accounts : 320
Account #/PIN/amount/type
30 39743 57.35 b
44 61405 68.96 l
112 65800 3.92 b
130 99874 65.3 b
161 48824 59.48 b
183 4722 75.81 b
235 50804 85.69 b
401 73906 44.65 l
419 68304 58.31 b
426 29149 82.44 h
449 62817 42.13 l
452 18922 22.35 b
454 5793 53.95 b
457 48771 18.28 b
543 94931 64.29 b
552 26496 21.97 l
625 7397 7.38 l
702 58385 56.14 l
703 90972 79.98 b
704 60991 67.49 b
750 59714 1.28 b
785 88449 26.22 h
795 65444 56.14 b
804 31144 18.62 b
885 13792 43.58 b
890 18796 15.34 l
899 6985 32.17 l
963 1250 48.1 b
972 53340 78.65 b
991 13580 78.9 b
1006 87487 79.48 l
1016 68223 35.94 b
1035 35381 -5.65 b
1037 81037 32.48 l
1048 67448 43.68 h
1084 56621 -3.87 b
1110 11267 38.43 l
1138 12495 57.09 l
1144 63647 41.35 l
1162 885 70.4 l
1173 86247 87.49 l
1190 19290 47.46 b
1193 64383 50.97 b
1250 95763 20.54 b
1255 79134 43.14 b
1267 703 56.56 b
1327 59552 59.01 b
1343 64371 25.71 b
1348 62159 65.64 h
1405 21255 40.77 l
1412 20401 -3.5 b
1432 58372 44.71 b
1450 66436 -6.16 l
1615 73915 -9.58 l
1663 49569 28.61 h
1671 7996 34.23 l
1712 29205 41.05 l
1729 87887 37.81 l
1732 22151 40.75 b
1747 7592 23.67 b
1784 73887 2.11 l
1793 81931 71.35 b
1818 22338 -2.11 h
1822 53806 34.93 l
1836 85556 53.67 l
1931 87479 48.09 h
2060 38075 40.99 l
2065 12417 0.83 l
2084 48876 81.26 l
2151 6690 89.79 b
2159 36903 24.42 b
2314 91712 80.18 b
2318 43482 20.5 b
2337 97807 67.57 l
2338 53320 -9.26 b
2340 75243 89.1 b
2392 96953 56.87 b
2407 29469 28.96 h
2417 59186 26.21 l
2485 58115 68.55 l
2495 59941 88.83 b
2533 21138 -2.07 h
2664 46347 39.19 l
2668 48734 86.06 b
2776 33734 22.36 b
2817 40419 82.87 h
2820 67948 56.01 h
2934 46083 26.09 b
2940 85702 31.58 b
2957 7458 61.05 h
2960 25924 34.81 b
2964 76744 58.02 b
3045 36676 89.72 l
3174 26725 68.29 l
3263 34876 56.28 l
3320 43045 83.07 l
3340 63489 47.37 h
3371 73263 12.5 b
3376 27381 62.01 b
3381 46292 52.62 b
3389 64952 10.97 b
3402 8925 46.66 l
3479 83533 76.3 b
3482 552 18.7 b
3489 88267 53.4 l
3516 90543 82.12 b
3533 82337 65.25 l
3580 98535 24.93 l
3646 2776 70.65 l
3647 73904 -3.0 b
3734 44 58.02 b
3792 454 70.95 b
3793 90890 83.91 b
3806 27588 -4.3 h
3822 90702 79.68 b
3887 85695 86.6 l
3904 26284 74.71 b
3906 43822 5.77 b
3915 31784 22.42 b
4007 28113 33.79 b
4044 6040 32.17 b
4053 74331 55.88 b
4066 89187 12.34 l
4190 32533 12.97 b
4287 53646 86.31 l
4288 41006 64.87 l
4295 8496 12.95 l
4331 1048 89.13 h
4334 44288 -1.16 h
4371 67657 86.12 l
4383 77802 43.2 b
4424 64665 67.86 l
4444 80426 83.79 l
4647 89812 -6.48 b
4657 87224 77.68 b
4665 30625 45.63 l
4718 18143 34.66 b
4722 40750 65.86 b
4735 34190 40.11 b
4771 17530 30.83 b
4781 6558 41.25 h
4875 27533 25.21 b
4876 10963 -3.19 b
4931 90030 81.78 b
4936 97635 -9.65 l
4952 97843 10.82 b
5011 52318 6.79 h
5237 55389 36.57 h
5243 69178 57.16 h
5287 11663 25.89 b
5307 8153 87.16 b
5350 79610 15.43 b
5361 9935 11.45 l
5380 66797 76.56 l
5381 64936 8.07 l
5389 97603 61.38 b
5438 55361 81.37 b
5444 59803 33.95 b
5461 17635 40.47 l
5556 15867 47.04 l
5657 58517 41.35 l
5670 10457 89.19 l
5686 47774 41.41 b
5695 13381 16.34 b
5702 45350 15.86 b
5704 12957 38.53 l
5763 96554 76.71 b
5793 85695 48.98 l
5799 45657 19.93 l
5800 64288 31.35 h
5836 71412 48.94 b
5840 19033 31.95 b
5867 7503 89.7 b
5876 59720 36.81 b
5924 235 19.61 l
5951 79088 -1.95 h
5965 51348 -8.87 h
6008 94066 37.37 l
6040 1343 89.18 b
6067 98956 44.11 l
6083 65461 33.62 b
6216 14875 36.44 l
6247 34053 25.53 b
6284 36978 73.49 h
6292 74735 57.04 l
6347 2668 75.79 h
6436 74295 12.39 l
6446 18599 16.13 h
6475 52065 4.43 l
6496 37568 -5.8 h
6502 2392 22.71 b
6554 47618 67.98 h
6558 11747 41.64 l
6621 55380 23.01 b
6671 49077 8.98 l
6676 89835 56.52 l
6690 97936 34.86 l
6724 58826 6.66 l
6725 61671 42.25 b
6744 82934 83.46 b
6789 91327 51.82 l
6797 38745 56.38 l
6811 57589 24.83 h
6820 77271 17.37 b
6903 30704 9.16 b
6953 92084 -5.83 b
6978 83479 47.66 h
6985 59809 9.41 h
7205 19425 48.81 l
7224 77205 20.42 l
7271 76789 62.9 h
7293 24287 83.07 l
7300 28352 89.75 b
7381 86502 43.86 b
7397 67757 -5.49 l
7448 33389 5.76 h
7458 6811 67.74 b
7479 4044 44.6 b
7487 9204 15.15 b
7503 72340 84.1 b
7507 65011 45.48 b
7530 51793 3.09 b
7533 97684 76.84 b
7568 12960 37.56 b
7588 68527 48.37 l
7589 68140 16.13 b
7592 70899 -6.14 h
7603 13376 -4.2 l
7607 58253 56.73 b
7618 86671 38.8 b
7635 82964 42.06 b
7648 21818 33.86 h
7657 17971 64.7 b
7684 4781 36.45 b
7757 15287 56.6 l
7774 91016 6.55 l
7802 86724 -2.18 b
7807 41190 4.4 b
7843 49531 80.79 b
7887 14771 67.93 b
7914 64718 66.58 h
7936 57648 14.78 h
7948 41732 44.05 b
7971 79658 65.68 h
7996 90112 22.14 b
8075 20452 79.65 b
8096 48247 23.45 l
8113 11615 81.16 l
8115 12664 70.92 b
8140 59682 77.31 b
8143 17507 74.52 l
8153 78462 45.2 b
8223 33402 0.41 b
8247 60161 75.05 b
8249 91450 0.26 b
8253 15307 -2.09 l
8267 18685 65.71 l
8304 34007 -4.47 l
8352 3516 64.64 l
8372 95799 75.7 h
8385 18528 87.26 h
8449 41729 16.25 h
8462 85876 46.08 l
8496 1822 3.46 b
8501 88506 14.48 l
8506 50449 62.2 h
8517 84444 70.22 b
8527 30785 40.85 l
8528 95951 16.81 b
8535 83793 49.98 b
8599 11836 56.95 l
8685 60795 82.59 l
8734 85438 74.24 h
8745 86008 68.65 h
8771 58096 66.3 l
8796 80130 40.4 b
8824 60183 52.48 b
8826 64424 37.19 b
8876 24647 29.9 l
8907 71035 40.65 l
8922 27914 64.72 b
8925 75840 61.48 b
8943 19175 10.82 l
8956 91162 56.37 b
8993 73371 41.37 b
9033 51173 24.47 b
9069 86446 42.6 l
9077 8501 54.79 b
9088 58993 51.87 b
9134 65704 82.78 b
9149 30452 60.77 b
9175 2820 82.26 b
9178 37293 48.81 b
9186 16820 9.91 b
9187 5836 54.59 l
9204 41432 27.39 b
9205 54424 33.37 b
9264 87607 21.85 l
9290 21193 35.11 b
9414 5237 0.04 l
9425 99414 73.19 b
9439 86475 44.27 l
9469 34334 36.7 b
9531 5965 39.01 l
9552 35670 39.27 b
9569 18943 32.3 b
9610 19069 43.56 h
9658 32314 14.6 b
9682 88907 66.69 l
9714 11110 33.53 b
9720 79264 60.23 b
9743 72407 23.11 l
9803 82485 85.4 l
9809 41084 -7.15 b
9812 23174 25.42 b
9835 50235 80.57 l
9871 96216 12.22 l
9874 64657 33.8 l
9935 25686 2.67 l
9941 77300 9.8 b

b = basic, they support regular withdrawals and diposits
l = low savings, Every deposit or withdrawal recalculates the balance after the transaction and deposits and additions 1% of the new balance.
h = Every deposit adds and additional 5% to the new balance, but every withdrawal has a flat deduction of $10.00 on top of the withdrawal.


That is for the letters beside the numbers in account.txt

Well explain what, specifically, you need help with. i.e. X method ]doesn't work, and it is supposed to do Y. Or I need help with reading in the file. etc.

Yes, dumping your homework into 4 posts with no code tags and no specific questions is not likely to yield a lot of constructive advice.

//amount of accounts : 320
Account #/PIN/amount/type
30 39743 57.35 b
44 61405 68.96 l
9935 25686 2.67 l
9941 77300 9.8 b

Posting hundrends of lines will help us understand but if you just posted a few line like I did wouldn't ?

Thanks for the replies, I have been working on the code since I put it up. I figured out how to withdraw and deposit and how to incorperate the different account types. i was just having a slight problem with the account and PIN, I figured it out by recreating the code into...

do{
account1 = ui.getKeyPadInt;
account2=reader.readInt();
if (account1=account2){
state = ENTER_PIN
}
while (account1!=account2)

Thats essentially what I did, I also did something similar to that for the PIN. So thats it its solved thanks for your replies, have fun in the future!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.