what i have so far is a few prompts that allow you to fill a list with user entered names. the user can continue to enter names until they choose 'n', which breaks the loop.
basically my problem is that once i get the number of students i need to create a loop that will create an arraylist for each student so that i can fill each list with individual grades. i just dont know if this can be done. im not really sure of a better way to do it, but if you guys know one im very open to suggestions.
btw, this isnt an assignment. just something im trying to do to get better.
here is my code so far:
//*********************************************************************************
// Main.java Nathan Gibson
//
// A simple java gradebook to keep track of students and grades.
//*********************************************************************************
import java.util.*;
public class Main
{
public static void main(String[]args)
{
//initialize Scanner
Scanner sc = new Scanner(System.in);
//initializes a list for student
ArrayList students = new ArrayList();
char yes;
do{
System.out.println("Would you like to add a student(y/n)? ");
String line = sc.nextLine();
yes = line.charAt(0);
if(yes == 'y')
{
System.out.println("Please enter the student's name");
String name = sc.nextLine();
students.add(name);
}
else
{
System.out.println("Contents of students: " + students);
}
}while(yes == 'y');
}
}
thanks!

New Topic/Question
Reply



MultiQuote










|