1

I made a class client and made set and get for every parameter I face this problem when the program run compiler discard the lines below the statement "Enter client name" and display "Enter client national ID" that's the complete code suppose that the classes is already made

import java.util.Scanner;

public class Main {


    public static void main(String[] args) 
    {
        System.out.println("\t\t\t********************\t\t\t");
        System.out.println("\t\t\t*Simple Bank System*\t\t\t");
        System.out.println("\t\t\t********************\t\t\t");
        Client client=new Client();
        int accountNum=1;
        int sAccountNum=1;
        Bank bank=new Bank();
       CommercialClient ComClient=new CommercialClient();
       Account account=new Account();
       Scanner user_input= new Scanner(System.in);


       System.out.println("select your choice   \n"+"------------------------------\n"+"1-Create new accountt\n"+"2-display bank data\n"+"3-Exit\n");


       int x;

       x = user_input.nextInt();   
       while(x!=3)

       {    
       if(x!=1&&x!=2)

       {

           System.out.println("\t\t\tPlease enter correct choice !\t\t\t");
       }

       else

       {

           if(x==1)

           {

               System.out.println("chose the client type :\n\n"+"1-Client\n"+"2-Commercial Client\n");

               x = user_input.nextInt();   


               if(x!=1&&x!=2)

               {

                   System.out.println("\t\t\tPlease enter correct choice !\t\t\t");

               }

               else

               {

                   if(x==1)

                   {

                       String input;

                       System.out.println("\nEnter client name :");
                       System.out.flush();                   
                       input=user_input.nextLine();

                       client.setName(input);

                       System.out.println("Enter client nationa ID :");

                       input=user_input.nextLine();

                       client.setNationalID(input);

                       System.out.println("\nEnter client Address:");

                       input=user_input.nextLine();

                       client.setAddress(input);

                       System.out.println("\nEnter client phone :");

                       input=user_input.nextLine();

                       client.setPhone(input);


                       System.out.println("\nchose the account type :\n\n"+"1-Normal account\n"+"2-Special account\n");

                       x = user_input.nextInt();

                       if(x!=1&&x!=2)

                       {
                           System.out.println("\t\t\tPlease enter correct choice !\t\t\t");


                        }

                       else

                       {

                           if(x==1)

                           {

                               System.out.println("Enter the beginning balance :");

                               x = user_input.nextInt();

                               account.setBalance(x);                                                            

                               account.setAcoount_Number(accountNum++);

                               client.setAccount(account);

                               bank.addAccount(account);

                               bank.addClient(client);

                           }

                           else 

                           {

                               System.out.println("Enter the beginning balance :");

                               x = user_input.nextInt();

                               account.setBalance(x);

                               account.setAcoount_Number(sAccountNum);

                               bank.addAccount(account);

                               bank.addClient(client);

                            }

                       }

                   }

                   else

                   {

                       String input;

                       System.out.println("\nEnter Commercial name :");

                       input=user_input.nextLine();

                       ComClient.setName(input);

                       System.out.println("Enter  Commercial ID :");

                       input=user_input.nextLine();

                       ComClient.setCommercialID(input);

                       System.out.println("\nEnter Commercial Address:");

                       input=user_input.nextLine();

                       ComClient.setAddress(input);

                       System.out.println("\nEnter Commercial phone :");

                       input=user_input.nextLine();

                       ComClient.setPhone(input);

                       System.out.println("chose the account type :\n\n"+"1-Normal account\n"+"2-Special account\n");

                       x = user_input.nextInt();

                       if(x!=1&&x!=2)

                       {

                           System.out.println("\t\t\tPlease enter correct choice !\t\t\t");

                       }

                             else

                       {

                           if(x==1)

                           {

                               System.out.println("Enter the beginning balance :");

                               account.setBalance(x);

                               account.setAcoount_Number(accountNum++);

                               bank.addAccount(ComClient.account);

                               bank.addClient(ComClient);

                            }

                                 else 

                           {

                               System.out.println("Enter the beginning balance :");

                               account.setBalance(x);

                               account.setAcoount_Number(sAccountNum);

                               bank.addAccount(account);

                               bank.addClient(ComClient);

                            }

                       }   

                   }

    }

           }

           else

           {

               bank.display();
               System.out.println("System closed");

           }

       }
        System.out.println("select your choice   \n"+"------------------------------\n"+"1-Create new accountt\n"+"2-display bank data\n"+"3-Exit\n");
        x = user_input.nextInt(); 
       }   
       System.out.println("System closed");
    }

}
Tom Sebastian
  • 3,123
  • 4
  • 24
  • 50
  • 1
    Possible duplicate of [Skipping nextLine() after using next(), nextInt() or other nextFoo() methods](http://stackoverflow.com/questions/13102045/skipping-nextline-after-using-next-nextint-or-other-nextfoo-methods) – thegauravmahawar Oct 19 '15 at 10:42
  • 1
    @thegauravmahawar there is no other `nextFoo` method. – SomeJavaGuy Oct 19 '15 at 10:43
  • Does it work if you call System.out.flush() after each print – Sammy Oct 19 '15 at 10:45
  • @KevinEsche: yes, but that's part of the title of the thread he's referring to – Stultuske Oct 19 '15 at 10:45
  • your code is working as expected in my system. – Naman Gala Oct 19 '15 at 10:45
  • @Stultuske that´s true, but the content of the question that he did provide to be a duplicate is different of this content. They are, judging this code, not related. But the code provided here shouldn´t cause any problems either, so i´d say that this isn´t the full code, or the code that is generating the problem. – SomeJavaGuy Oct 19 '15 at 10:48
  • Show us the complete code. Also, when program runs, its the *JVM* that skips things / throws errors. The compiler (unless you are talking about JIT, which you most probably aren't) does nothing :) – TheLostMind Oct 19 '15 at 10:51
  • Also working on mine, once I remove calls to set members of client – Sammy Oct 19 '15 at 10:51
  • you suggest coping it to a new project ?!! – youka mohye Oct 19 '15 at 11:32

0 Answers0