java programming
View Answers
June 6, 2008 at 6:05 PM
Hi friend,
import java.awt.*;
import java.applet.Applet;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
import javax.swing.event.*;
//This class defines one field in a record
public class ATM extends Applet {
// when applet is started, this is called automatically by the applet super class
public void init() {
// add panel to applet - the ATMPanel.
add(new ATMPanel());
}
static class ATMPanel extends Panel {
// setting up a pin that is needed for the atm
private static String PIN= "5803";
int accountmoney = 5000000;
//constants that provide state information for the atm
private static final int WAIT_FOR_CARD = 1;
private static final int WAIT_FOR_PIN = 2;
private static final int MENU_DISPLAYED = 3;
private static final int TRANSFER_MONEY = 4;
private static final int DISBURSE_MONEY = 5;
private static final int CHECK_BALANCE = 6;
private static final int SAVING_ACC = 7;
// text area that most likely contains the output from the ATM. Look up on google 'java TextArea' to view javadoc.
private TextArea mScreen= new TextArea("", 6, 45, TextArea.SCROLLBARS_NONE);
// some buttons
Button mEnter= new Button("Enter");
Button mClear= new Button("Clear");
Button mCancel= new Button("Cancel");
JButton Receipt = new JButton("Receipts Slot");
Button Quit = new Button("Quit");
JButton Cash = new JButton("Cash Slot");
private JLabel something = new JLabel("Yeah");
private String mPin= "";
private String Transfer= "";
private int Transfer1;
private int state = WAIT_FOR_CARD; // the current state of the ATM
public ATMPanel() {
// set the graphical layout for the applet.
setLayout(new BorderLayout());
// dont allow the text area to be editable
mScreen.setEditable(false);
// a listener that acts as a callback function for the keypad. when the keypad is pressed, this is called
ActionListener keyPadListener = new ActionListener(){
public void actionPerformed(ActionEvent e){
key(Integer.parseInt(((Button) e.getSource()).getLabel()));
}
};
// create keypad with 10 buttons
JPanel keypad= new JPanel(new GridLayout(0,3));
for(int i=1; i<10; i++) {
Button btn= new Button(String.valueOf(i));
// add keyPadListener as action listener to each button, the listener will get called when a button is pressed
btn.addActionListener(keyPadListener);
keypad.add(btn);
}
June 6, 2008 at 6:06 PM
keypad.add(new Label());
Button btn= new Button("0");
btn.addActionListener(keyPadListener);
keypad.add(btn);
// what to do when the enter button is clicked
mEnter.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// call the method enter() when enter is pressed.
enter();
}
});
// see enter() - same idea
mClear.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
clear();
}
});
// same idea as enter()
mCancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e){
cancel();
}
});
// same idea as enter()
Receipt.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e){
receipt();
}
});
// same idea as enter()
Quit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
quit();
}
});
// same idea as enter()
Cash.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
cash();
}
});
// add enter, clear, receeipt, quit, and cancel buttons to panel
Panel controls= new Panel(new GridLayout(3,2));
controls.add(mEnter);
controls.add(mClear);
controls.add(mCancel);
controls.add(Receipt);
controls.add(Quit);
controls.add(Cash);
add("North", mScreen);
add("Center", keypad);
add("South", controls);
mScreen.setText("Enter your card and press a number key.");
}
June 6, 2008 at 6:10 PM
private void key(int key) {
switch (state) {
case WAIT_FOR_CARD: // waiting for card
clear();
mScreen.setText(
"Card accepted.\n" +
"Welcome to ICICI Bank.\n" +
"Please enter your pin...");
state = WAIT_FOR_PIN;
break;
case WAIT_FOR_PIN: // waiting for pin
// accept number as part of pin
if (mPin.length() == 0)
mScreen.setText("");
mPin += String.valueOf(key);
mScreen.setText(mScreen.getText() +"*");
break;
case MENU_DISPLAYED:
// treat number as menu selection
switch(key){
case 1:
TransMoney();
break;
case 2:
DispenseMoney();
break;
case 3:
CheckBalance();
break;
case 4:
DispenseMoney();
break;
default:
InvalidOption();
}
break;
case TRANSFER_MONEY:
// treat number as part of amount to transfer
if(Transfer.length() == 0)
mScreen.setText("");
Transfer += String.valueOf(key);
mScreen.setText(mScreen.getText() + key );
break;
case DISBURSE_MONEY:
// treat number as part of amount to disburse
if(Transfer.length() == 0)
mScreen.setText("");
Transfer += String.valueOf(key);
mScreen.setText(mScreen.getText() + key );
break;
case CHECK_BALANCE:
break;
}
}
// called (by action listener) whenever a enter button is pressed
// what to do when enter is pressed according to various states of the ATM - could have been a switch statement like key()
private void enter(){
if (state == WAIT_FOR_CARD)
return;
if (state == WAIT_FOR_PIN){
// check pin
if(mPin.equals(PIN)){
// pin correct, display menu
menu();
}
else {
// pin incorrect, display message
clear();
mScreen.setText("Invalid pin, try again (it's " +PIN +")");
}
}
if (state == TRANSFER_MONEY) {
// perform transfer
Transfer1 = Integer.parseInt(Transfer);
accountmoney += Transfer1;
Transfer = "";
Transfer1 = 0;
menu();
}
if (state == DISBURSE_MONEY) {
// perform disburse
Transfer1 = Integer.parseInt(Transfer);
accountmoney -= Transfer1;
Transfer = "";
Transfer1 = 0;
menu();
}
}
June 6, 2008 at 6:10 PM
private void clear() {
if (state == WAIT_FOR_CARD)
return;
if (state == WAIT_FOR_PIN) {
mScreen.setText("");
mPin= "";
}
}
// called (by action listener) whenever cancel button is pressed
private void cancel() {
menu();
}
private void menu() {
// display menu
state = MENU_DISPLAYED;
clear();
mScreen.setText(
"1. Transfer money\n" +
"2. WITHDRAWAL money\n" +
"3. Check balance\n"+
"4. SAVING");
}
// called (by action listener) whenever receipt button is pressed
private void receipt() {
// display popuup
JOptionPane.showMessageDialog(null, "successfully withdrawal.", "Inane warning",
JOptionPane.WARNING_MESSAGE);
}
// called (by action listener) whenever cash button is pressed
private void cash(){
JOptionPane.showMessageDialog(null, "Transfer your many.", "Inane warning",
JOptionPane.WARNING_MESSAGE);
}
private void quit() {
// quit application
System.exit(0);
}
private void TransMoney() {
clear();
mScreen.setText("How much money would you like to transfer? ...");
state = TRANSFER_MONEY;
}
private void DispenseMoney() {
clear();
mScreen.setText("How much money would you like to take out? ...");
if (Transfer1 > accountmoney) {
mScreen.setText("You can't have more money than you already have");
}
state = DISBURSE_MONEY;
}
private void CheckBalance() {
state = CHECK_BALANCE;
clear();
mScreen.setText("This is the amount of money u have in your account.\n" +
" ---> " + accountmoney);
}
private void InvalidOption() {
clear();
mScreen.setText("You have choose the incorrect option. Try again");
}
}
// the main method that creates a frame, and adds your panel to it so that you can see it.
public static void main(String[] argv) {
Frame frame= new Frame("Simple ATM Example");
frame.add(new ATMPanel());
frame.setSize(500,400);
frame.setResizable(true);
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
}
---------------------------
Thanks
Related Tutorials/Questions & Answers:
Java ProgrammingJava Programming Hi,
What is
Java Programming? How I can learn
Java Programming in one month?
Thanks
java programming java programming Companies and people often buy and sell stocks... in question
Implement the program described above using the
Java programming language...
programming method you want to accomplish this task.
Both your stack and queue
Advertisements
java programming java programming Companies and people often buy and sell stocks... in question
Implement the program described above using the
Java programming language...
programming method you want to accomplish this task.
Both your stack and queue
Java ProgrammingJava Programming Write a
Java program that prompt user to input a number of students in a class. Then,
prompt user to input the studentÃ?¢ââ??‰â??¢s
programming mark. Determine how many student get
A+ and A for their grade
java programmingjava programming Write a
Java program that prompt user to input a number of students in a class. Then,
prompt user to input the studentâ??s
programming mark. Determine how many student get
A+ and A for their grade and how many
java programmingjava programming how to write a coding for simple login form in netbeans
java programmingjava programming what is taxonomy tree why we use that concept in
java
hierarchical taxonomy is a tree structure of classifications for a given set of objects
Java ProgrammingJava Programming Using
Java Frame form, help me develop a GPA calculating device, able to show
Grade and points together, and using MySQL database
Java ProgrammingJava Programming Using
Java Frame form, help me develop a GPA calculating device, able to show
Grade and points together, and using MySQL database
JAVA PROGRAMMINGJAVA PROGRAMMING Write an OVERLOADED FUNCTION in
java that swaps(interchanges) 2 user given numbers.(one integer and one float value) and displays the result after swapping.
Invoke the function in a class
java programmingjava programming how to count the no. of constants in a user given string??
plzz help
java programmingjava programming Write a complete
Java Program that correctly does the following:
prints out first 1000 numbers (not including 1000) with a statement indicating whether it is even or not..
Output: Example
Number 0 - Even
java programmingjava programming Hi friends, if i create one project what are the step i can make...... i need step by step procedure
java programmingjava programming WAP to calculate the sum of:
x + x(square)/2 + x(cube)/3 +.......... x(to the power n)/n
java programmingjava programming supose i have a text field in
java (like in gmail home page u have username field )
so i want to fill that field automatically by taking record from the database so is there any mechanism in
java to handle
java programmingjava programming Hi, do u have any idea about these lines?
Hashtable<Integer,JLabel> labels = new Hashtable<Integer,JLabel>();
labels = new Hashtable<Integer,JLabel>
java programmingjava programming Hi friends i need simple login form coding using two labels,two textfields and two buttons in netbeans without using database connection. . if you know that logic please tell
java programmingjava programming Hi friend if you have any idea about this statement please tel me...
String qry1="select * from custentry1 where custid='"+custno
java programmingjava programming Hi friends, i need a simple login form source code. in that program i have two labels,two text fields and two buttons namely ok and cancel buttons. how to write for that one using netbeans without database
java Programmingjava Programming Based on the following algorithm, write a
Java Program
Start defining the MyClass class.
Declare the class?s myField data field.
Initialize the data field.
Start defining the SetField() method.
Set
Java ProgrammingJava Programming Assume that bank maintains two kinds of accounts...://www.roseindia.net/tutorial/
java/core/bankAccountApplication.html
thnk...://www.roseindia.net/answers/viewqa/
Java-Beginners/27008-q-in-java.html
java programmingjava programming How can be uesd in graphiclly view for user inter (x,y) cordinate and show the output shart point to end point.
java code,,????
import org.jfree.chart.*;
import org.jfree.chart.plot.PlotOrientation
java programmingjava programming How can be uesd in graphiclly view for user inter (x,y) cordinate and show the output shart point to end point.
java code,,????
import org.jfree.chart.*;
import org.jfree.chart.plot.PlotOrientation
java programmingjava programming How can be uesd in graphiclly view for user inter (x,y) cordinate and show the output shart point to end point.
java code,,????
import org.jfree.chart.*;
import org.jfree.chart.plot.PlotOrientation
Java programmingJava programming Hello! Is anybody able to do this task: I need to find the percentage of words distribution between parts of speech. I have to mark nouns, verbs, adjectives and perpositions like that: to the end of noun
java programmingjava programming abstract class demo
{
void play()
{
System.out.println("hello");
}
void play2()
{
System.out.println("hi there");
}
}
class abs extends demo
{
public static
Java ProgrammingJava Programming A developer wants you to develop a simple take away restaurant order service.
The system reads from a file containing information about the restaurants (such as
the name, place and menu). The system then allows
JAVA PROGRAMMINGJAVA PROGRAMMING WAP to generate the following Series
* * * * *
* * * *
* * *
* *
*
class Pyramid{
public static void main(String[] args
Java programmingJava programming To make a fraction to a representation base 16 (i.e. hexadecimal) we can multiply it by 16, and the resultant integer part is the first digit of the base-16 representation. Multiplying the fraction left over
java programmingjava programming A name is ALREADY in a string variable in memory. The string is called NAME or NAME$ . The variable holds a person's name with a space between the first and family name.
WILLIAM (space) JONES
java programmingjava programming WAP to find the longest word from a user given string.
The given code finds the longest word from the string.
import java.util.*;
class LongestWord
{
Scanner input=new Scanner(System.in
java programmingjava programming WAP to accept 10 strings from the user and find out the string with maximum length and print the same.
Here is a code that accepts 10 strings from the string and stored into array and then find
java programmingjava programming Hi, now am analysing one project from that project the below module was came. why we use that module what is the use of this module........
public void Start_Clustering()
{
int Clusters
java programmingjava programming A computer is used to count the votes in an election. At the start of the election, the number of candidates standing is entered. Suppose this value is N â?? candidates will then be numbered 1 to N
Java Socket ProgrammingJava Socket Programming Hi,
What is
Java Socket
Programming? Can anyone give the examples of
Java Socket
Programming?
Thanks
Hi,
Please see the tutorial:Overview of Networking through
JAVA
Thanks
Java Programming LanguageJava Programming Language Hi,
For beginner which
programming concepts is important?
Discuss the importance of
Java programming language... please let's know how to use
Java in developing web applications?
Thanks
Java programming approchJava programming approch What are the approaches that you will follow for making a program very efficient
Programming problem - Java Beginners it difficult to learn
java programming? Based on my survey it seems that
java programming is the hardest part of their studies.. I also want to know...
Programming problem Good afternoon Ma'am/Sir,
Can you help me
programming java qus.programming java qus. write a import statement that import all the inner class of outer class .outer class must not be imported
programming java qus.programming java qus. write a import statement that import all the inner class of outer class .outer class must not be imported
programming java qus.programming java qus. write a import statement that import all the inner class of outer class .outer class must not be imported
programming java qus.programming java qus. write a import statement that import all the inner class of outer class .outer class must not be imported
programming java qus.programming java qus. write a import statement that import all the inner class of outer class .outer class must not be imported