I need to print out the titles for family members being stored in an array, but I am having issues with the report. It prints out all the stored names, instead of the ones that belong to each family member and one line for each. I'm new with arrays so, it's a learning process for me, thanks for the help!
import java.util.Scanner;
public class Geneology
{
private String[] family;
private int[][] memberName;
private int size;
private int sizeNo;
private String[] titles;
private Scanner input = new Scanner(System.in);
public String[] setTitles()
{
size = 0;
sizeNo = 0;
System.out.printf("\nYou will be entering the titles for your family members."
+"\nHow many family members will be entered?"
+"\nAlso, enter the highest number of titles of one of the family members: ");
size = input.nextInt();
sizeNo = input.nextInt();
input.nextLine();
memberName = new int[size][sizeNo];
family = new String[size];
titles = new String[sizeNo];
for(int a = 0; a < memberName.length; a++)
{
System.out.printf("\nEnter name of member %d: ", a+1);
family[a] = input.nextLine();
for(int b = 0; b < memberName[a].length; b++)
{
System.out.printf("\nEnter title %d for %s: ", b+1, family[a]);
titles[b] = input.nextLine();
}
}
return titles;
}
public void printTitles()
{
for(int a = 0; a < memberName.length; a++)
{
System.out.printf("\n%S's TITLES\n%s\n", family[a], titles[a]);
}
This is the output that I am getting:
D's TITLES
sonnephewdaughterniece
A's TITLES
sonnephewdaughterniece