I am trying to write a program to accept user input. This program will be run in Command Prompt.
My expected output is something as below :
Pls select option : (User will input S for Sales, D for Daily Order, C for Collection, E for Exit) Once the use input his/her input, If/Else will be used to verify the option chosen. If the option chose are not one of the S, D, C or E, the program will request the user input again.
I need to know how to write the code. The help that all of you offered is most appreciated. Thanks.
To get a string value from the user after displaying a message you could use a simple method like the following.
I leave it to you to add it to your program or use it as you would like.
/** Displays the input message on the console to
* prompt the user for input. Returns a line of
* text entered from the console.
*/
private String getInput(String message){
String userInput = "";
try{
System.out.println(message);
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
userInput = br.readLine();
}catch(IOException ioe){
System.err.println("IOException: " + ioe.getMessage());
}
return userInput;
}
After i have received the input from user, i need to write some code to determine the selection of the user...
For example:
Option : S
After the character is input, i will use if/else to see which option the user choose. By the way, every option will perform certain function....such as select S will perform Sales, select D will perform Dailly Order, and C will perform a dosplay of the current sales info and E will exit the program...
The most important thing is that i do not know how to write the if/else...