Write a program to display the following menu and accept a choice number. If an invalid choice, appropriate error message must be displayed. Otherwise the choice number entered must be displayed.
MENU
(1)- create a data file
(2)- display a data file
(3)- edit a data file
(4)- exit
Choice:
Answers
Program to display the following menu and accept a choice number which is mention in the question is given below
Output:
(1)- create a data file
(2)- display a data file:
(3)- edit a data file:
(4)- exit
Choice:
2
Your choice is 2
Explanation:
As in the question their is no such language of programming is given so we have used Java Programming language to create a program .
Program:
import java.util.*; // import package
import java.lang.*; // import package
import java.io.*; // import package
class Main // main class
{
// main method
public static void main (String[] args) throws java.lang.Exception
{
try // try block
{
Scanner scr=new Scanner(System.in); //creating the object of scanner class
int choice; // variable declaration
System.out.println("(1)- create a data file:");
System.out.println("(2)- display a data file:");
System.out.println("(3)- edit a data file:");
System.out.println("(4)- exit");
System.out.println("Choice:");
choice=scr.nextInt();
if(choice>4 || choice<1)
System.out.println("Wrong Choice.");
else{
System.out.println("Your choice is "+ choice);
}
}catch(Exception ex){
return;}
}
}
Following are the description of the program :
Create a scanner class object to read the input from user. Print the menu of choices and then read the user's choice with scanner object. Then check whether user has entered a valid choice or not. If choice is invalid (choice<1|| choice>4) then print "Wrong Choice" message, Otherwise print the user's choice.
Learn More:
Write a program to design a menu in visual basic. https://brainly.in/question/12988159