Class MenuItem

java.lang.Object
trial.gaurav.menu.MenuItem

public class MenuItem extends Object
The `MenuItem` class represents an item in the menu with a unique choice number, a name, and an associated action.
  • Field Details

    • choice

      private int choice
    • name

      private String name
    • action

      public Action action
  • Constructor Details

    • MenuItem

      public MenuItem(int ch, String nm, Action act)
      Constructs a new `MenuItem` object with the given choice, name, and action.
      Parameters:
      ch - The unique choice number of the menu item.
      nm - The name of the menu item.
      act - The associated action to be performed when the menu item is selected.
  • Method Details

    • display

      public void display()
      Displays the menu item on the console. The menu item is displayed in the format: "choice. name".
    • getChoice

      public int getChoice()
      Gets the choice number of the menu item.
      Returns:
      The choice number of the menu item.