How can i make a java program that will run the following 1. When run it should show "Welcome Select from menu" "Press 1 for show price", "press 2 to show discount" "press 3 to exit" The program should ask for user input and give an error message if wrong number is entered. 2. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How can i make a java program that will run the following 1. When run it should show "Welcome Select from menu" "Press 1 for show price", "press 2 to show discount" "press 3 to exit" The program should ask for user input and give an error message if wrong number is entered. 2.

18th May 2017, 4:35 AM
Dennis Joel
2 Answers
+ 4
first display the message to the screen then put a if statement if(input == 1) then show price if(input == 2) then show discount then write if(input != 1&&input != 2) then gives a message
18th May 2017, 4:47 AM
chris
chris - avatar
+ 1
public class Program { public static void main(String[] args) { boolean doesResponseRecived = false; System.out.println("Welcome Select from Menu"); while(!doesResponseRecived) { System.out.println("Press 1 for show price"); System.out.println("press 1 for show discount"); System.out.println("press 3 for exit"); java.util.Scanner sb = new java.util.Scanner(System.in); String resp = sb.next(); if(resp.equals("1") || resp.equals("2") || resp.equals("3")) { System.out.println("We have got your response'); doesResponseRecived = true; }else{ System.out.println("Enter either 1,2 or 3"); } } } }
18th May 2017, 5:56 AM
Vishal Prajapati