-
February 22nd, 2012, 11:33 AM
#1
Need help with a code for an ATM program
Hi im a beginner at this stuff but i want to be able to understand everything thats going on and not have to keep posting on here lol
on that note im creating an ATM program in class, pretty simple one that does deposit, withdrawal and views the account balance but i cant seem to get past the configuration for the pin number input help? im using eclipse
this is what i have so far:
public static void main(String args[]) {
{
int cardnumber;
int pinNumber;
char accountType;
boolean anotherTransaction;
// ask user for Card
System.out.println("Please slide your card in the reader below");
//bring in user card number
// ask user for pin
System.out.println("Please enter your PIN number and hit enter");
String name= JOptionPane.showInputDialog("Please Enter Your pinNumber");
//check PIN number for validity
importjavax.swing.JOptionPane
importjava.util.Scanner;
int inumber=integer.parseint(pinNumber);
string pinNumber = Interger.parseint(pinNumber);
if iNumber >=0001 && iNumber <= 9999;
System.out.println(iNumber);
-
February 22nd, 2012, 11:40 AM
#2
Re: Need help with a code for an ATM program
also could someone explain how System.in.read() handles integers ?
thanks
-
February 22nd, 2012, 01:09 PM
#3
Re: Need help with a code for an ATM program
Hi,
Please, use code tags to post your code. It makes easier to read
If you are a beginner, In my opinion you shouldn't start using swing. First, try to learn the Java language.
To read an integer from console:
Code:
Scanner sc = new Scanner(System.in);
int value = sc.nextInt();
For instance
Code:
import java.io.*;
import java.util.*;
public class Test {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
System.out.print("Write an integer: ");
int value = sc.nextInt();
System.out.println("Value is: " + value);
}
}
Output:
Write an integer: 6576
Value is: 6576
Using of System.in.read() is quite different, because it takes bytes not numbers. Look at this piece of code:
Code:
import java.io.*;
public class Test {
public static void main(String[] args) throws IOException {
System.out.print("Write an integer: ");
int value = System.in.read();
System.out.println("");
System.out.println("Value is: " + value);
}
}
Output:
Write an integer: 4
Value is: 52
Another example:
Write an integer: 245345
Value is: 50
That's because System.in.read() only reads one byte. In first example 52 is ASCII representation of 4 in decimal. In second example it only takes the first byte you typed (2) and 50 is the representation of 2.
Although it's not difficult to deal with streams (System.in is an InputStream), I think you should start reading data with Scanner until you understand how the language works (packages, classes, objects, methods, imports,...)
Hope this helps!
Albert.
Please, correct me. I'm just learning.... and sorry for my english :-)
-
February 22nd, 2012, 09:08 PM
#4
Re: Need help with a code for an ATM program
it all makes sense now .
thanks!
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|