Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I feel like my program is only a couple of lines away from being complete. I bel

ID: 3602401 • Letter: I

Question

I feel like my program is only a couple of lines away from being complete. I believe i need another loop but i am struggling with where it needs to go. Code is pasted at the bottom below the program requirements.

Requirements

Your program will ask the user for the name of the family (Last Name). Example dialog box below.

Prompt the user for the number of family members. Make sure that you include the families name in the message.

Prompt the user to enter the first name of each family member. If there are 2 family member, you will use the same dialog box. If the family has 10 members, you need to ask for each name one at a time.

Once all names have been collected, display the entire family.

Ask the user if they want to enter a new family.

If the user clicks 'Yes', then repeat the instructions starting with the name of the family.

You do not have to save the data from the last family.

If the user clicks 'No', then send a message to come back again and end the program.

This program will need two different loops.

Instantiations of variables should be outside of all loops, with the exception of any For Loop counters.

DO NOT store the family members once their names have been displayed. For example, if you plan the enter two families, ask for the details of the first family and display their names, then use the same variables to collect the next family. Do not use arrays, Lists or Array Lists for this assignment. These storage types are covered in a later chapter.

MY CODE

package membership.as;

import javax.swing.JOptionPane;

public class MembershipAS { // Start Class MembershipAS

    public static void main(String[] args) {// Start Main Method
        String familyName = "";
        String familyMembers = "";
        double numberOfFamily = 0.0;
        int count = 1;
        String answer = "";

        familyName = JOptionPane.showInputDialog(null, "What is the name of the family?");

        familyMembers = JOptionPane.showInputDialog(null, "How many members in the " + familyName + " family?");
        numberOfFamily = Double.parseDouble(familyMembers);

      
      
        while (count <= numberOfFamily) {
          
            JOptionPane.showInputDialog(null, "Enter name " + count);
            count++; // increase by one

        }
        JOptionPane.showMessageDialog(null, "Members of the " + familyName + " family " + answer + familyName + " " + answer + familyName);
    }// End Main Method
}// End Class MembershipAS

Explanation / Answer

import javax.swing.JOptionPane;

public class MembershipAS { // Start Class MembershipAS

public static void main(String[] args) {// Start Main Method

String familyName = "";

String familyMembers = "";

double numberOfFamily = 0.0;

int count = 1;

String answer = "";

while(true)

{

familyName = JOptionPane.showInputDialog(null, "What is the name of the family?");

familyMembers = JOptionPane.showInputDialog(null, "How many members in the " + familyName + " family?");

numberOfFamily = Double.parseDouble(familyMembers);

while (count <= numberOfFamily) {

  

JOptionPane.showInputDialog(null, "Enter name " + count);

count++; // increase by one

}

JOptionPane.showMessageDialog(null, "Members of the " + familyName + " family " + answer + familyName + " " + answer + familyName);

int res = JOptionPane.showConfirmDialog (null, "Do you want to continue?");

if(res == JOptionPane.YES_OPTION)

continue;

else

break;

}

}// End Main Method

}// End Class MembershipAS