ATM Java code
This is an ATM kind of machine.
Programmed without exceptions.
......................................................import javax.swing.*;
/**@author LEE (Mafanga Lolito)
*
* @version ATM PIN Checker 1.0 (Without Exceptions)
*
* @since : 04 September 2012
*/
public class ATM{
public static void main ( String args []){
int countWrong = 3;
int pin = 123;
int thePin = 0;
while ( thePin != pin){
String thePinString= JOptionPane.showInputDialog(null,"Enter your Password :","Umbrella Corporation!");
thePin = Integer.parseInt(thePinString);
// Counts wrong pins entered
countWrong--;
//if the count is = 3, meaning the wrong pin is entered 3 times
//the program breaks and displays the message
if ( countWrong == 0 && thePin != pin){
JOptionPane.showMessageDialog(null,"ACCESS REVOKED!\n","Umbrella Corporation.", JOptionPane.ERROR_MESSAGE);
JOptionPane.showMessageDialog(null,"UNAUTHRIZED ACCESS!!","Umbrella Corporation.", JOptionPane.ERROR_MESSAGE);
JOptionPane.showMessageDialog(null, "PROGRAM TERMINATED!!.\n\nContact your System Administrator to get the new Pin.","Umbrella Corporation", JOptionPane.ERROR_MESSAGE);
break;
}
//Displays to the user how many tries left till the ATM card gets blocked
if ( thePin != pin && countWrong ==2){
JOptionPane.showMessageDialog(null,"ACCESS DENIED !\n"+ countWrong+ " tries left...\n","Wrong Pin Number!", JOptionPane.WARNING_MESSAGE);
}
else if ( thePin != pin && countWrong ==1){
JOptionPane.showMessageDialog(null,"ACCESS DENIED !\n"+ countWrong + " try left...\n","Wrong Pin Number!", JOptionPane.WARNING_MESSAGE);
}
if ( thePin == pin){
JOptionPane.showMessageDialog(null," " +
"AUTHORIZED !","ACCESS GRANTED, WELCOME!", JOptionPane.PLAIN_MESSAGE);
JOptionPane.showMessageDialog(null,"\t\t\tChoose the language.\n(Enter the corresponding number to the language of your choice.)", " Chose The Language.", JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog(null,"1. English.\n2. Afrikaans. \n3. isiXhosa or \n4. Sesotho.", "Select Your Language.", JOptionPane.INFORMATION_MESSAGE);
}
}
}
}
Comments
Post a Comment
Be real!