The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Jul 2017 |
| Last Sign in: | 304 Weeks Ago, 1 Day Ago |
| Questions Answered: | 15833 |
| Tutorials Posted: | 15827 |
MBA,PHD, Juris Doctor
Strayer,Devery,Harvard University
Mar-1995 - Mar-2002
Manager Planning
WalMart
Mar-2001 - Feb-2009
Please see questions in bold text in the coding below. I am confused on some of this. Any help is appreciated. Thank you.
Â
package membership2;
Â
import java.util.Arrays;
Â
import javax.swing.JOptionPane;
Â
public class Membership2 {
Â
   public static void main(String[] args) {
      // intitize
      String ans;         // Catch the users answers
      int cont;           // Continue
      int fNum;           // Number of family members
      String family[];    // Array that will contain all family
                                    // members.
     Â
      do {
         // Ask how many members of the family
         ans = JOptionPane.showInputDialog(null,
               "How many members in the family?n" +
               "You will be prompted for each members first name.");
        Â
                       // Convert the string answer to a number
         fNum = Integer.parseInt(ans);
        Â
                       // Store the family names into an array
         family = storeFamily(fNum);
        Â
                       // Print the family list
         printFamily(family);
        Â
                       // Sort the family
         family = sortFamily(family);
        Â
                       // Print the sorted family list
         printFamily(family);
        Â
                       // Ask if user wants to enter another family
         cont = JOptionPane.showConfirmDialog(null,
               "Do You want to add another family?",
               "Membership", JOptionPane.YES_NO_OPTION);
        Â
      }while(cont == JOptionPane.YES_NO_OPTION);
     Â
      JOptionPane.showMessageDialog(null, "Please come again");
Â
   }    // End of main method
Â
       // Is this an accurate description for the coding below: Adds a method that sorts the array and returns the results
   private static String[] sortFamily(String[] family) {
      Arrays.sort(family);
      return family;
   }
Â
       // Is this an accurate description for the coding below: Adds method that displays result of sorted array
   private static void printFamily(String[] family) {
      String str = "Members of the family : n";
      for(String s : family) {
         str = str + s + "n";
      }
// Why do I get an error message on the line below?
      JOptionPane.showMessageDialog(null, str "Message", JOptionPane.INFORMATION_MESSAGE);
   }
Â
       // Is this a correct description of the method below: Adds method that counts and stores new family member input
   private static String[] storeFamily(int count) {
     Â
      String[] family = new String[count];
     Â
      String lastname = JOptionPane.showInputDialog(null,
            "What is the name of the family ?");
              Â
      // The line below initializes an array and executes as many times as there are family members?
      for(int i=0 ;i< count ;i++) {
        Â
         String firstname = JOptionPane.showInputDialog(null,
               "Please enter the each first name of family member one at a time. ");
      Â
         family[i] = firstname + " " + lastname;
        Â
      }
     Â
      return family;
   }
Â
}
----------- Â ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly