Advertisement
Guest User

JAVA -1 Python +1

a guest
Nov 1st, 2013
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.70 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class simpleBank {
  3.  
  4.  
  5. public static void main(String[] args) {
  6. Scanner keyboard = new Scanner(System.in);
  7. int pin = 1234, pin_attempts = 3, user_pin_try, user_choice;
  8. double balance = 340.0, withdraw_limit = 500, user_transfer_money;
  9. boolean continue_banking = true, input_valid;
  10.  
  11. // A simple greeting
  12. System.out.println("Welcome to Jan Bank");
  13. System.out.println("");
  14.  
  15. //login part of the script
  16. System.out.println("Please enter your 4 digit PIN.");
  17. user_pin_try = keyboard.nextInt();
  18. while (pin_attempts > 1) {
  19. if (user_pin_try == pin) {
  20. break;
  21. }
  22. else {
  23. pin_attempts -= 1;
  24. System.out.println("Wrong PIN, you have " + pin_attempts + " attempt(s) remaining.");
  25. System.out.println("Please enter your 4 digit PIN.");
  26. user_pin_try = keyboard.nextInt();
  27. }
  28. }
  29. // once they have logged in
  30. if (pin == user_pin_try){
  31. System.out.println("Access Granted");
  32. while (continue_banking) {
  33. System.out.println("");
  34. System.out.println("What would you like to do?");
  35. System.out.println(" Enter 1 to withdraw money");
  36. System.out.println(" Enter 2 to deposit money");
  37. System.out.println(" Enter 3 to view your current balance");
  38. System.out.println(" Enter 4 to quit");
  39.  
  40. user_choice = keyboard.nextInt();
  41.  
  42. // 1, they want to take money out of their account
  43. input_valid = false;
  44. if (user_choice == 1) {
  45. while (input_valid == false) {
  46. System.out.println("How much money would you like to withdraw? (Enter 0 to cancel)");
  47. System.out.println("Your current balance is $" + balance);
  48. System.out.println("You can withdraw up to $" + withdraw_limit);
  49. user_transfer_money = keyboard.nextDouble();
  50. // 0, the user wants to cancel
  51. if (user_transfer_money == 0) {
  52. input_valid = true;
  53. System.out.println("Action Canceled");
  54. }
  55. // the user goes over the limit
  56. else if (user_transfer_money > withdraw_limit){
  57. System.out.println("You cannot withdraw $" + user_transfer_money + ", limit is $" + withdraw_limit);
  58. }
  59. // they do not have enough money
  60. else if (user_transfer_money > balance){
  61. System.out.println("You cannot withdraw $" + user_transfer_money + ", you only have $" + balance);
  62. }
  63. // the input is correct
  64. else{
  65. balance -= user_transfer_money;
  66. System.out.println("You new balance is $" + balance);
  67. input_valid = true;
  68. }
  69. }
  70. }
  71. // the user wants to add money
  72. input_valid = false;
  73. else if (user_choice == 2) {
  74. while (input_valid == false){
  75. System.out.println("How much would you like to deposit? (Enter 0 to cancel");
  76. System.out.println("Your current balance is $" + balance);
  77. user_transfer_money = keyboard.nextDouble();
  78. // 0, the user wants to cancel
  79. if (user_transfer_money == 0) {
  80. input_valid = true;
  81. System.out.println("Action Canceled");
  82. }
  83. else {
  84. balance += user_transfer_money;
  85. System.out.println("You new balance is $" + balance);
  86. input_valid = true;
  87. }
  88. }
  89. }
  90. // user want to check balance
  91. else if (user_choice == 3) {
  92. System.out.println("Your current balance is $" + balance);
  93. }
  94. else if (user_choice == 4) {
  95. System.out.println("Ending Session");
  96. }
  97. else {
  98. System.out.println("Invalid Input");
  99. }
  100. }
  101. }
  102. }
  103.  
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement