atm help

having trouble getting my atm machine working

Page 1 of 1

1 Replies - 2046 Views - Last Post: 20 December 2009 - 02:44 AM Rate Topic: -----

#1 kerplunk0091  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 19-December 09

atm help

Posted 19 December 2009 - 09:40 PM

ok so i have to create an atm program. the program allows for input of a pin and then searches a raf in the first screen, it then moves onto a second menu where the option to withdrawal, check balance, or make a quick withdrawal comes up, and from there either goes to another screen and exits and so on, my problem is i can not figure out how to get the account number into my other classes and because java does not have global variable i can not figure it out, any help is appreciated, and for now my code looks bad but i was planning to clean it up when i was finished with it


import java.text.*;  
import javax.swing.*;
import java.awt.event.*;
import java.awt.Container;  
import java.awt.*;  
import java.io.*;


public class ATM extends JFrame
{
  static final int RECLEN =16; 
  static final int BASEREC=1000;
  private JFrame mainFrame;
  private JButton EnterButton;
  private JTextField PersonalID;
  private JLabel EnterPIN;
  
 
 
  public ATM() 
  
  {
	mainFrame = new JFrame("ATM");
	EnterButton = new JButton("Enter");  
	EnterPIN = new JLabel("Please enter your four digit PIN and press enter");
	PersonalID = new JTextField(5);
	

	  
	Container c = mainFrame.getContentPane(); 
	 
	c.setLayout(new FlowLayout());
	
	   
	c.add(EnterPIN);
	c.add(PersonalID);
	c.add(EnterButton);
	
	
	  
	EnterButton.setMnemonic('e');
   
	mainFrame.setSize(350,150);
	
	
	  
	mainFrame.addWindowListener(new WindowAdapter()
	{
	  public void windowClosing(WindowEvent e) {System.exit(0);}
	});
	
	  
	EnterButtonHandler ehandler = new EnterButtonHandler(); 
	EnterButton.addActionListener(ehandler);	  
 
   

 
	mainFrame.show();
  } 
  
  
  class EnterButtonHandler implements ActionListener
  {
	public void actionPerformed(ActionEvent e) 
		
	{
	/*	String fileName="products.dat";
		String acctstring, amtstring, pricestring;
		int acct;
		int amt;
		int recnum;
		double price;
		long filelen, position, setbytepos;
		
	
		InputStreamReader isr=
			new InputStreamReader(System.in);
		BufferedReader br=
			new BufferedReader(isr);
			
	
	try{
			RandomAccessFile raf =
			new RandomAccessFile(fileName, "rw");
		
		filelen=raf.length(); 
		
		

		*/
	 
	  String instring;	  
	  int invalue;
	  
	   
	  instring=PersonalID.getText(); 
		  
	 
	  invalue= Integer.parseInt(instring)- BASEREC;
			
			position=(invalue-1)*RECLEN;
	  
	  if (instring.equals("") || position<0 || position>(filelen-1) )
	  {
		  JOptionPane.showMessageDialog(null, "Invalid please try again",
		  "Event Handler Message",JOptionPane.INFORMATION_MESSAGE);
	  }
	  raf.seek(position);
	  acct=raf.readInt();
	  setbytepos=raf.getFilePointer();
	  amt=raf.readInt();
		
	  mainFrame.setVisible(false);
	  
	  new options();
	  
	  
	}
	catch(FileNotFoundException a) 
			  {
			  }
	 catch( IOException b)
	 {
	 }
	  
	  
	}
  }  
  

  class ExitButtonHandler implements ActionListener
  {
	public void actionPerformed(ActionEvent e)
	{
	  System.exit(0);
	}
  }  

  public static void main(String args[])
  throws java.io.IOException
  {
	new ATM(); 
  }

}  


thats my atm class which then calls


import java.text.*;  
import javax.swing.*;
import java.awt.event.*;
import java.awt.Container;  
import java.awt.*;  
import java.io.*;

public class options extends JFrame 
{
  static final int RECLEN =16; 
  static final int BASEREC=1000;
  private JFrame mainFrame, mainFrame2, mainFrame3;
  private JButton EnterButton, WithdrawlButton, CheckBalance,WithdrawlTwenty,WithdrawlForty,WithdrawlSixty,WithdrawlEighty, WithdrawlHundred;
  private JTextField PersonalID;
  private JLabel EnterPIN, QuickWithdrawl;
  
 
  
	  public  options()
  {
	  mainFrame2 = new JFrame("Options");
	WithdrawlButton = new JButton("Withdrawl"); 
	CheckBalance = new JButton("Check Balance");
	WithdrawlTwenty = new JButton("$20");
	WithdrawlForty = new JButton("$40");
	WithdrawlSixty = new JButton("$60");
	WithdrawlEighty = new JButton("$80");
	WithdrawlHundred = new JButton("$100");
	QuickWithdrawl = new JLabel("Please choose an amount for quick withdrawl");
	
	
	Container d = mainFrame2.getContentPane(); 
	 
	d.setLayout(new FlowLayout());
	
	   
	d.add(WithdrawlButton);
	d.add(CheckBalance);
	d.add(QuickWithdrawl);
	d.add(WithdrawlTwenty);
	d.add(WithdrawlForty);
	d.add(WithdrawlSixty);
   	d.add(WithdrawlEighty);
   	d.add(WithdrawlHundred);	
   		
   	WithdrawlButton.setMnemonic('w');
   	CheckBalance.setMnemonic('c');
   	WithdrawlTwenty.setMnemonic('2');
   	WithdrawlForty.setMnemonic('4');
   	WithdrawlSixty.setMnemonic('6');
   	WithdrawlEighty.setMnemonic('8');
   	WithdrawlHundred.setMnemonic('1');
   
	mainFrame2.setSize(300,200);	
   
   
   mainFrame2.addWindowListener(new WindowAdapter()
	{
	  public void windowClosing(WindowEvent e) {System.exit(0);}
	});
	
	
   WithdrawlButtonHandler whandler = new WithdrawlButtonHandler(); 
	WithdrawlButton.addActionListener(whandler); 
		
	CheckBalanceHandler chandler = new CheckBalanceHandler(); 
	CheckBalance.addActionListener(chandler);
	
   	WithdrawlTwentyHandler thandler = new WithdrawlTwentyHandler(); 
	WithdrawlTwenty.addActionListener(thandler); 
		
   	WithdrawlFortyHandler fhandler = new WithdrawlFortyHandler(); 
   WithdrawlForty.addActionListener(fhandler);
	 
   	WithdrawlSixtyHandler shandler = new WithdrawlSixtyHandler(); 
	WithdrawlSixty.addActionListener(shandler);
	 
   	WithdrawlEightyHandler ehandler = new WithdrawlEightyHandler(); 
	WithdrawlEighty.addActionListener(ehandler); 
		
   	WithdrawlHundredHandler hhandler = new WithdrawlHundredHandler(); 
	WithdrawlHundred.addActionListener(hhandler); 
   
   
	mainFrame2.show();
	  
	  
  }

  class WithdrawlButtonHandler implements ActionListener
  {
	public void actionPerformed(ActionEvent e) 
		
	{
	
		new withdrawl();
		mainFrame2.dispose();
	  
	  
	}
  }  
  
  class CheckBalanceHandler implements ActionListener
  {
	public void actionPerformed(ActionEvent e) 
		
	{
	
		 JOptionPane.showMessageDialog(null, "Your acount has: $" ,
		 "Event Handler Message",JOptionPane.INFORMATION_MESSAGE);
	  
	  
	}
  }  
  
  class WithdrawlTwentyHandler implements ActionListener
  {
	public void actionPerformed(ActionEvent e) 
		
	{
		 JOptionPane.showMessageDialog(null, "20" ,
		 "Event Handler Message",JOptionPane.INFORMATION_MESSAGE);
	  mainFrame2.dispose();
	  new Thankyou();
	  
	}
  }  
  
  class WithdrawlFortyHandler implements ActionListener
  {
	public void actionPerformed(ActionEvent e) 
		
	{
		JOptionPane.showMessageDialog(null, "40" ,
		 "Event Handler Message",JOptionPane.INFORMATION_MESSAGE);

	  
	  
	}
  }  
  
  class WithdrawlSixtyHandler implements ActionListener
  {
	public void actionPerformed(ActionEvent e) 
		
	{
		JOptionPane.showMessageDialog(null, "60",
		 "Event Handler Message",JOptionPane.INFORMATION_MESSAGE);
		
		

	  
	  
	}
  }  
  
  class WithdrawlEightyHandler implements ActionListener
  {
	public void actionPerformed(ActionEvent e) 
		
	{
	JOptionPane.showMessageDialog(null, "80" ,
		 "Event Handler Message",JOptionPane.INFORMATION_MESSAGE);

	  
	  
	}
  }  
  
  class WithdrawlHundredHandler implements ActionListener
  {
	public void actionPerformed(ActionEvent e) 
		
	{
	JOptionPane.showMessageDialog(null, "100" ,
		 "Event Handler Message",JOptionPane.INFORMATION_MESSAGE);

	  
	  
	}
  }  
  
  
  
  
  
  

  

} 


and that class is part of my problem i can not figure out how to get the account information into this class so that i can get the money info


any help is appreciated and thanks in advanced

Is This A Good Question/Topic? 0
  • +

Replies To: atm help

#2 chaos386  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 5
  • View blog
  • Posts: 28
  • Joined: 27-February 09

Re: atm help

Posted 20 December 2009 - 02:44 AM

easy
change your options class file to include this

private String acc;
   /* public  options()*/ public  options(int acc)
  {
	 this.acc = acc;
	  mainFrame2 = new JFrame("Options");
	WithdrawlButton = new JButton("Withdrawl"); 
	CheckBalance = new JButton("Check Balance");
   .........



and the AMT class to
......
	  acct=raf.readInt();
	  setbytepos=raf.getFilePointer();
	  amt=raf.readInt();
		
	  mainFrame.setVisible(false);
	  
	  /*new options(); change to */	new options(acct);



and there you go all done :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1