Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3978476
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:03:08+00:00 2026-05-20T05:03:08+00:00

good day… i am creating an address book program… i used a switch in

  • 0

good day… i am creating an address book program… i used a switch in my main menu… and planning to create an another switch for my edit menu… my problem is.. I don’t know how to go back to my main switch… this is my 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 a = new AddressBook();
        a.entry = new AddressBookEntry[100];
        int option = 0;
        while (option != 6) {
            String content = "Choose an Option\n\n"
                    + "[1] Add an Entry\n"
                    + "[2] Delete an Entry\n"
                    + "[3] Update an Entry\n"
                    + "[4] View all 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 i = 0;
        for (; i < counter; i++) {
            JOptionPane.showMessageDialog(null, new JTextArea(entry[i].getInfo()));
        }
    }

    public void editMenu() {
        int option = 0;
        while (option != 6) {
            String content = "Choose an Option\n\n"
                    + "[1] Edit Name\n"
                    + "[2] Edit Address\n"
                    + "[3] Edit Phone No.\n"
                    + "[4] Edit E-mail address\n"
                    + "[5] Go Back to 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 to edit: ");
        for (int i = 0; i < counter; i++) {
            if (entry[i].getName().equals(EName)) {
                entry[i].setName(JOptionPane.showInputDialog("Enter new name: "));
            }
        }
    }
}

please help… thanks in advance 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T05:03:08+00:00Added an answer on May 20, 2026 at 5:03 am

    To return to the caller, you can use return; instead of break;

    In editMenu

                case 5:
                    return;
    

    However, i suspect your problem is that

    while (option != 6) {
    

    should be

    while (option != 5) {
    

    You could also use a label to break out of the while loop which would do the same thing here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good day! I am a newbie on creating database... I need to create a
Good day! I am using Xcode 3.1.4 and iPhone SDK 2.2.1. I am creating
Good day all, for running multiple threads concurrently is it advisable to create different
Good day! I encountered the following error upon running my JSP program. java.lang.IllegalStateException: PWC3991:
Good day pythonians, I want to make a custom dictionary with two main features:
Good Day, I used position:absolute for many div's in my website. I have used
Good day, We just converted our web application .NET 1.1 to .NET 2.0. We
Good day, I'm having a problem with asp.net 2.0 viewstate. Basically, I want to
Good day, In visual studio 2005, when I drop a webcontrol in the designer,
Good Day All we are trying to do is inside a trigger make sure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.