Question
Practice modularization Objective of this activity:- converting given code to modularised code menu.java package lecture4; import java.util.Scanner; public class Menu { public static void main(String[]
- Practice modularization
Objective of this activity:- converting given code to modularised code
menu.java
package lecture4;
import java.util.Scanner;
public class Menu {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int menuSel;
System.out.println("Menu");
System.out.println("1. Enter data");
System.out.println("2. Display data");
System.out.println("3. Exit");
System.out.println("Enter selection:");
menuSel = in.nextInt();
switch(menuSel){
case 1: System.out.println("Menu istem 1");
break;
case 2: System.out.println("Menu item 2");
break;
case 3: System.out.println("Exiting....");
break;
default: System.out.println("Invalid selection!");
}
in.close();
}
}
- Create a method to display menu that will display the menu which is given in file and ask to enter their selection and return that selection to calling method. Call this method in main method where there is a need to print menu.
- Move the switch case to a separate method which will take menuSel as input and print necessary details.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started