package Application; public class MenuManager { private Menu rootMenu; private Menu currentMenu; public MenuManager(Menu rootMenu){ this.rootMenu = rootMenu; this.currentMenu = rootMenu; } public void select(int i){ this.currentMenu = currentMenu.getMenu(i); } public void back() throws Exception { if(!this.inRootMenu()) this.currentMenu = this.currentMenu.getPreviousMenu(); else throw new Exception("Menu is a root menu, a previous menu doesn't exist"); } public Menu getCurrentMenu(){ return this.currentMenu; } public boolean inRootMenu(){ return this.currentMenu.equals(this.rootMenu); } }