0

It's a french class, so you might not understand some words but it doesnt really matter.I will translate some right now. Also we dont use scanner this session because we're new, they developped a thing called "keyboard (Clavier in french)" that takes the input. What is wrong with this code? Its a pizza facturation.

System.out.println("Hi this is a program to take the clients order");
       do { 
                System.out.println("do you want to produce a new bill ? (Y or y = YES, N or n = NO)");
                answer = Keyboard.readChar();
                while (answer != SMALL_Y && answer!= BIG_Y && answer!= SMALL_N && answer!= BIG_N){
                    System.out.println("*** INVALID ANSWER"); 
                    System.out.println("do you want to produce a new bill ? (Y ou y = YES, N ou n = NO)");
                    answer= Keyboard.readChar() ;
                }
                    if (answer == SMALL_Y || answer == BIG_Y ){
                        nbFacture = nbFacture + 1; //thats for the bill number
                        System.out.println ("What is the client phone number?");
                        numTel = Keyboard.readString() ;
                        System.out.println ("What is the client Adress?");
                        adresseLivraison = Keyboard.readString() ;
                        System.out.println ("How many meals between 1 and 4 do you plan to order) ");
                        menu = Keyboard.readInt() ; 


                    } 



        }while(answer != BIG_N|| answer!= SMALL_N); 

I translated everything in english so you can understand the most out of it. The keyboard function is the same as scanner, it's used in order to take the input.

EDIT When I run this code, and select YES. I get this 2 SOP at the same time :What is the client phone number? What is the client Adress?

When I select NO, I get this : do you want to produce a new bill ? (Y or y = YES, N or n = NO) *** INVALID ANSWER do you want to produce a new bill ? (Y or y = YES, N or n = NO)

  • You ask "What's wrong with this code?" but you don't tell us what actually happens when you try to compile and run it vs. what you want to happen. – Joseph Sible-Reinstate Monica Oct 20 '18 at 21:10
  • @JosephSible you are right. im new here im sorry, i just edited my question. thank your pointing that out –  Oct 20 '18 at 21:17
  • Appears that `readChar()` is a wrapper around `Scanner.next()` and `readString()` is a wrapper around `Scanner.nextLine()`, which makes this question a duplicate of: [Scanner is skipping nextLine() after using next() or nextFoo()?](https://stackoverflow.com/q/13102045/5221149) – Andreas Oct 20 '18 at 21:21

0 Answers0