My assignment is to create a Java application to organize the list of graduates. The user will enter the student names and their associated concentration (1,2,3,4). The application should count the number of students in each concentration in a method DIFFERENT than the one where you're inputting the values. The output should include the list of student names and the count in each concentration
My problem: I can't figure out how to display the names. I used a for loop to run through the length of the array and concatenate them to a String variable. When I use i < array.length the output is a long list of nulls. But if I put i < 4, for example it works fine.
Any tips on what I'm doing wrong?
static final String[] concentrations= {"math", "science","english","web"};
public static void main(String[] args) {
// TODO Auto-generated method stub
String[] names = new String[500]; //stores student's names
int[] stuConc = new int[500]; //stores student's concentration pick
int[] concentCount = new int[concentrations.length];
input(names, stuConc);
count( stuConc, concentCount);
output(names, concentCount, concentrations);
}//end main
private static void input(String[] stuNames, int[] stuPick)
{
int i = 0;
do
{
stuNames[i] = JOptionPane.showInputDialog("Student's name: ");
stuPick[i] = Integer.parseInt(JOptionPane.showInputDialog("Your concentration: \n1. DTP\n2. INFS\n3. NTEL\n4. WDM"));
i++;
}
while(JOptionPane.showConfirmDialog(null, "Another student?")==JOptionPane.YES_OPTION);
}//end method
private static void output(String[] names, int[] concentCount, String[] concent)
{
String nameList="";
String concentCountList ="";
for(int i =0; i < names.length; i++) //where my problem is
{
nameList += names[i] + "\n";
}//end for
for(int i=0; i<concent.length; i++)
{
concentCountList += concent[i]+ ": "+ concentCount[i]+ "\n";
}//end for
nameList = nameList + concentCountList;
JOptionPane.showMessageDialog(null, nameList );
}//end output method
Thank you
I'm stumped on the method 'output'

New Topic/Question
Reply



MultiQuote




|