Guest User

Untitled

a guest
Jan 19th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. public void businessAccount()
  2. {
  3.  
  4.  
  5. int selection;
  6.  
  7. System.out.println("nATM main menu:");
  8. System.out.println("1 - View account balance");
  9. System.out.println("2 - Withdraw funds");
  10. System.out.println("3 - Add funds");
  11. System.out.println("4 - Back to Account Menu");
  12. System.out.println("5 - Terminate transaction");
  13. System.out.print("Choice: ");
  14. selection = input.nextInt();
  15.  
  16. if (selection > 5){
  17.  
  18. System.out.println("Invalid choice.");
  19. businessAccount();
  20.  
  21. }
  22. else if (selection < 1){
  23. System.out.println("Invalid choice.");
  24. businessAccount();
  25. }
  26. else {
  27.  
  28. switch(selection)
  29. {
  30. case 1:
  31. viewAccountInfo3();
  32. break;
  33. case 2:
  34. withdraw3();
  35. break;
  36. case 3:
  37. addFunds3();
  38. break;
  39. case 4:
  40. AccountMain.selectAccount();
  41. break;
  42. case 5:
  43. System.out.println("Thank you for using this ATM!!! goodbye");
  44. }
  45. }
  46. }
  47.  
  48. try{
  49. selection = input.nextInt();
  50. switch(selection){
  51. case 1:
  52. viewAccountInfo3();
  53. break;
  54. case 2:
  55. withdraw3();
  56. break;
  57. case 3:
  58. addFunds3();
  59. break;
  60. case 4:
  61. AccountMain.selectAccount();
  62. break;
  63. case 5:
  64. System.out.println("Thank you for using this ATM!!! goodbye");
  65. break;
  66. default:
  67. System.out.println("Invalid choice.");
  68. businessAccount();
  69.  
  70. }
  71. }catch(InputMismatchException e){
  72. //do whatever you wanted to do in case input is not an int
  73. }
  74.  
  75. InputStreamReader isr = new InputStreamReader(System.in);
  76. BufferedReader br = new BufferedReader(isr);
  77. String s = br.readLine();
  78. int selection = 0;
  79.  
  80. try{
  81. selection = Integer.parseInt(s);
  82. if(selection > 5 || selection < 1){
  83. System.out.println("Invalid choice.");
  84. businessAccount();
  85. }else{
  86. // your switch code here
  87. }
  88. // you can use @Nishant's switch code here. it is obviously better: using switch's default case.
  89. }catch(NumberFormatException ex){
  90. // throw new Exception("This is invalid input"); // or something like that..
  91. System.out.println("Invalid choice.");
  92. businessAccount();
  93. }
  94.  
  95. if (selection > 5)||(selection < 1){
  96. System.out.println("Invalid choice.");
  97. businessAccount();
  98. } else {
  99. //....rest code
  100. }
Add Comment
Please, Sign In to add comment