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[]

  1. 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!