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: | 336 Weeks Ago, 3 Days 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