Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void businessAccount()
- {
- int selection;
- System.out.println("nATM main menu:");
- System.out.println("1 - View account balance");
- System.out.println("2 - Withdraw funds");
- System.out.println("3 - Add funds");
- System.out.println("4 - Back to Account Menu");
- System.out.println("5 - Terminate transaction");
- System.out.print("Choice: ");
- selection = input.nextInt();
- if (selection > 5){
- System.out.println("Invalid choice.");
- businessAccount();
- }
- else if (selection < 1){
- System.out.println("Invalid choice.");
- businessAccount();
- }
- else {
- switch(selection)
- {
- case 1:
- viewAccountInfo3();
- break;
- case 2:
- withdraw3();
- break;
- case 3:
- addFunds3();
- break;
- case 4:
- AccountMain.selectAccount();
- break;
- case 5:
- System.out.println("Thank you for using this ATM!!! goodbye");
- }
- }
- }
- try{
- selection = input.nextInt();
- switch(selection){
- case 1:
- viewAccountInfo3();
- break;
- case 2:
- withdraw3();
- break;
- case 3:
- addFunds3();
- break;
- case 4:
- AccountMain.selectAccount();
- break;
- case 5:
- System.out.println("Thank you for using this ATM!!! goodbye");
- break;
- default:
- System.out.println("Invalid choice.");
- businessAccount();
- }
- }catch(InputMismatchException e){
- //do whatever you wanted to do in case input is not an int
- }
- InputStreamReader isr = new InputStreamReader(System.in);
- BufferedReader br = new BufferedReader(isr);
- String s = br.readLine();
- int selection = 0;
- try{
- selection = Integer.parseInt(s);
- if(selection > 5 || selection < 1){
- System.out.println("Invalid choice.");
- businessAccount();
- }else{
- // your switch code here
- }
- // you can use @Nishant's switch code here. it is obviously better: using switch's default case.
- }catch(NumberFormatException ex){
- // throw new Exception("This is invalid input"); // or something like that..
- System.out.println("Invalid choice.");
- businessAccount();
- }
- if (selection > 5)||(selection < 1){
- System.out.println("Invalid choice.");
- businessAccount();
- } else {
- //....rest code
- }
Add Comment
Please, Sign In to add comment