Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Made by: Dylan G.
- * Date: 11-25/28-2010 Copyright :D
- */
- import javax.swing.JOptionPane; // Need this for all JOptionPane input boxes.
- public class ATM { // The class..
- public static void main(String[] args){ // YOU JUST NEED IT.
- int pinNumberReal = 1593; // All the variables
- double depositCash;
- double withdrawCash;
- double newBalance;
- int pinNumber;
- String withdraw = "withdraw";
- String deposit = "deposit";
- double currentBalance = 79; {
- String userPinNumber = JOptionPane.showInputDialog("Enter your pin number."); // Input box for user pin number, saves it as a string variable
- pinNumber = Integer.parseInt(userPinNumber); // Makes the string into a variable, a number variable.
- if (pinNumber == pinNumberReal && userPinNumber != null) { // If the user input pin number is correct then do continue
- String userDepositOrWithdraw = JOptionPane.showInputDialog("Would you like to deposit or withdraw money from your account?"); { // If the pinNumber is correct, then show input box for withdraw or deposit
- if (userDepositOrWithdraw.equalsIgnoreCase(deposit) && userDepositOrWithdraw != null) { // Takes the input from userWithdrawOrDeposit into lower case then matches it to deposit
- JOptionPane.showMessageDialog(null,"Your current balance is: " + currentBalance + "."); // Displays currentBalance
- String userDepositCash = JOptionPane.showInputDialog("Enter how much you would like to deposit."); // Input box and saves as the variable userDepositCash
- depositCash = Double.parseDouble(userDepositCash); // Makes the string from the input box a valid number variable
- if (depositCash < 0) { // If user tries to deposit a negative number, displays error
- System.err.println("You can't deposit money you don't have!"); // Displays error
- } else { // If depositCash isn't below 0, then do this:
- newBalance = currentBalance + depositCash; // Does the deposit from currentBalance
- JOptionPane.showMessageDialog(null,"Your current balance after deposit is: " + newBalance + "."); // Displays newBalance
- } // Closes the else statement that does then deposits then displays it
- } // Closes the things to do if userDepositOrWithdraw is deposit
- if (userDepositOrWithdraw.equalsIgnoreCase(withdraw) && userDepositOrWithdraw != null) { // Takes the input from userWithdrawOrDeposit into lower case then matches it to withdraw
- JOptionPane.showMessageDialog(null,"Your current balance is: " + currentBalance + "."); // Displays currentBalance
- String userWithdrawCash = JOptionPane.showInputDialog("Enter how much you would like to withdraw."); // Input box and saves as the variable userWithdrawCash
- withdrawCash = Double.parseDouble(userWithdrawCash); // Makes the string from the input box a valid number variable
- if (withdrawCash > currentBalance) { // If you withdraw more money than you have, error message
- System.err.println("You can't withdraw more money than you have!"); // Displays error
- } else { // If you have enough to withdraw from your currentBalance, then do this:
- newBalance = currentBalance - withdrawCash; // Does the withdraw from currentBalance
- JOptionPane.showMessageDialog(null,"Your current balance after withdraw is: " + newBalance + "."); // Displays newBalance
- } // Closes the else statement that does the withdraw and displays it
- } // Closes the things to do if userDepositOrWithdraw is withdraw
- if (!userDepositOrWithdraw.equalsIgnoreCase(withdraw) && (!userDepositOrWithdraw.equalsIgnoreCase(deposit))) { // If user inputs something besides "withdraw" or "deposit" then error message
- System.err.println("You entered " + userDepositOrWithdraw + " instead of deposit or withdraw."); // Displays errors
- } // Closes the error message if userDepositOrWithdraw isn't withdraw or deposit
- } // Closes the input box asking if deposit or withdraw
- } // Closes the things to do if pinNumber is correct.
- if (pinNumber != pinNumberReal){ // If the user inputs incorrect pin, error message
- System.err.println("Incorrect pin number."); // Displays error
- } // Closes the incorrect pinNumber error if-then
- } // Closes everything after the variable
- } // Closes the string[] args command
- } // Closes the class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement