Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M. Kroenke

1st Edition

0130086509, 978-0130086501

More Books

Students also viewed these Databases questions

Question

Explain the process of MBO

Answered: 1 week ago