java - how should i make my switch go back to main switch? -
good day... creating address book program... used switch in main menu... , planning create switch edit menu... problem is.. don't know how go main switch... main program:
import javax.swing.joptionpane; import javax.swing.jtextarea; public class addressbook { private addressbookentry entry[]; private int counter; public static void main(string[] args) { addressbook = new addressbook(); a.entry = new addressbookentry[100]; int option = 0; while (option != 6) { string content = "choose option\n\n" + "[1] add entry\n" + "[2] delete entry\n" + "[3] update entry\n" + "[4] view entries\n" + "[5] view specific entry\n" + "[6] exit"; option = integer.parseint(joptionpane.showinputdialog(content)); switch (option) { case 1: a.addentry(); break; case 2: break; case 3: a.editmenu(); break; case 4: a.viewall(); break; case 5: break; case 6: system.exit(1); break; default: joptionpane.showmessagedialog(null, "invalid choice!"); } } } public void addentry() { entry[counter] = new addressbookentry(); entry[counter].setname(joptionpane.showinputdialog("enter name: ")); entry[counter].setadd(joptionpane.showinputdialog("enter add: ")); entry[counter].setphoneno(joptionpane.showinputdialog("enter phone no.: ")); entry[counter].setemail(joptionpane.showinputdialog("enter e-mail: ")); counter++; } public void viewall() { int = 0; (; < counter; i++) { joptionpane.showmessagedialog(null, new jtextarea(entry[i].getinfo())); } } public void editmenu() { int option = 0; while (option != 6) { string content = "choose option\n\n" + "[1] edit name\n" + "[2] edit address\n" + "[3] edit phone no.\n" + "[4] edit e-mail address\n" + "[5] go main menu\n"; option = integer.parseint(joptionpane.showinputdialog(content)); switch (option) { case 1: editentry(); break; case 2: break; case 3: break; case 4: break; case 5: break; default: joptionpane.showmessagedialog(null, "invalid choice!"); } } } public void editentry() { string ename; ename = joptionpane.showinputdialog("enter name edit: "); (int = 0; < counter; i++) { if (entry[i].getname().equals(ename)) { entry[i].setname(joptionpane.showinputdialog("enter new name: ")); } } } }
please help... in advance :)
to return caller, can use return;
instead of break;
in editmenu
case 5: return;
however, suspect problem that
while (option != 6) {
should be
while (option != 5) {
you use label break out of while loop same thing here.
Comments
Post a Comment