Question: I need help with this Arraylist string program for java. I cant get the Students in Class to not print on repeat. It needs to

I need help with this Arraylist string program for java. I cant get the "Students in Class" to not print on repeat. It needs to say, "Students in Class: " and then 10. bc the nNumberStudents is an accessor. This is what i Have:

import java.util. Scanner; import java.io.*; import java.util.ArrayList; public class StudentsQuiz2 {

public static void main(String[] args) throws FileNotFoundException { ArrayList stuList = new ArrayList(); System.out.println("STUDENTS ROOSTER AND QUIZ AVERAGES"); System.out.println(""); generateStuList(stuList); for (int nIndex = 0; nIndex < stuList.size(); nIndex++) { printStudentsQuiz(stuList.get(nIndex)); } } //End of main method public static void printStudentsQuiz(StudentsQuiz myStudentsQuiz){ System.out.println("Students in class: " + myStudentsQuiz.getNumberStudents()); System.out.println(""); System.out.println("Student Name: "+ myStudentsQuiz.getFirstName() + " " + myStudentsQuiz.sLastName.toUpperCase()); System.out.println("Quiz Average: "+ myStudentsQuiz.calculateQuizAverage()); System.out.println(""); }//End printStudentsQuiz method public static void generateStuList(ArrayList list) throws FileNotFoundException { String sFileName = "Students.txt"; String sInputLine = ""; File fileToOpen = new File(sFileName); Scanner inputFile = new Scanner(fileToOpen); String[] saTokens = null; while (inputFile.hasNext()){ sInputLine = inputFile.nextLine(); saTokens = sInputLine.split("-"); StudentsQuiz stu = new StudentsQuiz(); stu.setFirstName(saTokens[0]); stu.setLastName(saTokens[1]); stu.setQuiz1(Integer.parseInt(saTokens[2])); stu.setQuiz2(Integer.parseInt(saTokens[3])); stu.setQuiz3(Integer.parseInt(saTokens[4])); list.add(stu); }//End while loop }//End generateStuList method }//End of StudentsQuiz2 class

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!