This site requires JavaScript, please enable it in your browser!
Greenfoot back
divinity
divinity wrote ...

2016/5/8

not getting the chance to re-enter the pin numbers

divinity divinity

2016/5/8

#
hi danpost I am building a banking system for my take home assignment. from the beginning, i am trying to implement a part where the user would enter their pin numbers. the program stated that it have i can either use the while or do while. i choose the latter. the while. the first part is asking the user to enter their 4 digit pin number. if the user mis-step and enter the wrong pin number, the user is given another chance to re-enter their pin. i put it in an if else construct and also use a do while in order to give the user another chance to re-enter their pin and for some reason it is not letting the user re-enter their pin, it just hit the first statement in the if construct and it just goes straight to ask for the user name . can u tell me where and why in the codes why it is not allowing the user to re-enter the pin when they have entered the wrong pin number. here is the codes i have used so far. PS. I am not finished building the system. here is the codes
 while(i<2)
        {
            
            System.out.println("please enter your 4 digit pin number");
            pin = userin.nextInt();
           
            if(pin == 1234)
            {
                System.out.println("you can begin your transaction");
                numtries++;
            }
            else if(pin != 1234)
            {
                System.out.println("incorrect pin number, try again");
            }
            
            do
            {
                if(pin != 1234)
                {
                    System.out.println("please re-enter your pin");
                }
            }while(pin == 1234);
            
            System.out.println("please enter the customer first name");
            String customer_firstname = userin.next();
            
            System.out.println("please enter the customer last name");
            String customer_lastname = userin.next();
            
            System.out.println("please enter customer ID");
            String customer_ID = userin.next();
            
            System.out.println("please enter menu type");
            System.out.println(" please enter type code: S");
            option = userin.next().charAt(0);
            
            System.out.println("please enter initial account balance");
            initialacct_bal = userin.nextDouble();
            
danpost danpost

2016/5/8

#
For one thing, I do not think you want to continue the loop if the pin entered was correct (see line 23). This is why it immediately jumps to doing the transactions. For another thing, you need to increment the value of 'i' somewhere (when the wrong pin number is entered or every time a pin number is entered). Line 10 seems to attempt to count the number of attempts; however, it will never increase but one time, when the correct pin is entered. Are both the 'i' and the 'numtries' fields trying to track the same thing? if so, that could complicate things.
divinity divinity

2016/5/8

#
hi danpost i fixed it and got it to work but now it stop it is not going to ask for the customer number number and the rest of the codes this is where it stop and do i have to put an increment. and what do i do now for it to continue here is where it stop
please enter your 4 digit pin number
1254
incorrect pin, please re-enter your pin
1234
danpost danpost

2016/5/8

#
divinity wrote...
hi danpost i fixed it and got it to work but now it stop it is not going to ask for the customer number number and the rest of the codes this is where it stop and do i have to put an increment. and what do i do now for it to continue...
Please show your newly revised code (for the entire 'while' loop -- like above).
divinity divinity

2016/5/8

#
here it is danpost as with the above snippet of output, there is where it stop
            System.out.println("please enter your 4 digit pin number");
            pin = userin.nextInt();
           
            if(pin != 1234)
            {
                System.out.println("incorrect pin, please re-enter your pin");
                i++;
            }
            else if(pin == 1234)
            {
                System.out.println("you can now start with your transaction");
            }
            
            do
           {
               if(pin == 1234)
               {
                   System.out.println("please re-enter your pin");
               }
           }while(pin != 1234);
           this is where it stop running. 
            
            System.out.println("please enter the customer first name");
            String customer_firstname = userin.next();
            
            System.out.println("please enter the customer last name");
            String customer_lastname = userin.next();
            
            System.out.println("please enter customer ID");
            String customer_ID = userin.next();
            
            
            System.out.println("please enter initial account balance");
            initialacct_bal = userin.nextDouble();
            
            System.out.println("which operation do you wish to do");
            
            System.out.println("please enter menu type");
            System.out.println(" please enter type code: S");
            option = userin.next().charAt(0);
            
danpost danpost

2016/5/8

#
You print a message that the user must re-enter the pin; but, you are not accepting any input there.
divinity divinity

2016/5/8

#
hi danpost where do i put the input because i am still getting the same result even after i put an input and what input do u think ah should put for it to work properly
danpost danpost

2016/5/8

#
divinity wrote...
hi danpost where do i put the input because i am still getting the same result even after i put an input and what input do u think ah should put for it to work properly
Remove lines 16 and 17 and replace line 19 with a copy of what is on line 2.
divinity divinity

2016/5/8

#
thank you danpost, it work, thanks you very much. much appreciated.
You need to login to post a reply.