Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.28 KB | None | 0 0
  1. /* Made by: Dylan G.
  2. * Date: 11-25/28-2010 Copyright :D
  3. */
  4.  
  5. import javax.swing.JOptionPane; // Need this for all JOptionPane input boxes.
  6.  
  7. public class ATM { // The class..
  8. public static void main(String[] args){ // YOU JUST NEED IT.
  9. int pinNumberReal = 1593; // All the variables
  10. double depositCash;
  11. double withdrawCash;
  12. double newBalance;
  13. int pinNumber;
  14. String withdraw = "withdraw";
  15. String deposit = "deposit";
  16. double currentBalance = 79; {
  17.  
  18. String userPinNumber = JOptionPane.showInputDialog("Enter your pin number."); // Input box for user pin number, saves it as a string variable
  19. pinNumber = Integer.parseInt(userPinNumber); // Makes the string into a variable, a number variable.
  20.  
  21.  
  22. if (pinNumber == pinNumberReal && userPinNumber != null) { // If the user input pin number is correct then do continue
  23.  
  24. 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
  25.  
  26. if (userDepositOrWithdraw.equalsIgnoreCase(deposit) && userDepositOrWithdraw != null) { // Takes the input from userWithdrawOrDeposit into lower case then matches it to deposit
  27. JOptionPane.showMessageDialog(null,"Your current balance is: " + currentBalance + "."); // Displays currentBalance
  28. String userDepositCash = JOptionPane.showInputDialog("Enter how much you would like to deposit."); // Input box and saves as the variable userDepositCash
  29. depositCash = Double.parseDouble(userDepositCash); // Makes the string from the input box a valid number variable
  30.  
  31. if (depositCash < 0) { // If user tries to deposit a negative number, displays error
  32. System.err.println("You can't deposit money you don't have!"); // Displays error
  33. } else { // If depositCash isn't below 0, then do this:
  34.  
  35. newBalance = currentBalance + depositCash; // Does the deposit from currentBalance
  36. JOptionPane.showMessageDialog(null,"Your current balance after deposit is: " + newBalance + "."); // Displays newBalance
  37.  
  38. } // Closes the else statement that does then deposits then displays it
  39. } // Closes the things to do if userDepositOrWithdraw is deposit
  40. if (userDepositOrWithdraw.equalsIgnoreCase(withdraw) && userDepositOrWithdraw != null) { // Takes the input from userWithdrawOrDeposit into lower case then matches it to withdraw
  41. JOptionPane.showMessageDialog(null,"Your current balance is: " + currentBalance + "."); // Displays currentBalance
  42. String userWithdrawCash = JOptionPane.showInputDialog("Enter how much you would like to withdraw."); // Input box and saves as the variable userWithdrawCash
  43. withdrawCash = Double.parseDouble(userWithdrawCash); // Makes the string from the input box a valid number variable
  44.  
  45. if (withdrawCash > currentBalance) { // If you withdraw more money than you have, error message
  46. System.err.println("You can't withdraw more money than you have!"); // Displays error
  47. } else { // If you have enough to withdraw from your currentBalance, then do this:
  48.  
  49. newBalance = currentBalance - withdrawCash; // Does the withdraw from currentBalance
  50. JOptionPane.showMessageDialog(null,"Your current balance after withdraw is: " + newBalance + "."); // Displays newBalance
  51.  
  52. } // Closes the else statement that does the withdraw and displays it
  53. } // Closes the things to do if userDepositOrWithdraw is withdraw
  54. if (!userDepositOrWithdraw.equalsIgnoreCase(withdraw) && (!userDepositOrWithdraw.equalsIgnoreCase(deposit))) { // If user inputs something besides "withdraw" or "deposit" then error message
  55. System.err.println("You entered " + userDepositOrWithdraw + " instead of deposit or withdraw."); // Displays errors
  56. } // Closes the error message if userDepositOrWithdraw isn't withdraw or deposit
  57. } // Closes the input box asking if deposit or withdraw
  58. } // Closes the things to do if pinNumber is correct.
  59. if (pinNumber != pinNumberReal){ // If the user inputs incorrect pin, error message
  60. System.err.println("Incorrect pin number."); // Displays error
  61. } // Closes the incorrect pinNumber error if-then
  62. } // Closes everything after the variable
  63. } // Closes the string[] args command
  64. } // Closes the class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement