Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help with last part of this java. I can get everything except recognizing the name at the end. I posted the requirements and both

Need help with last part of this java. I can get everything except recognizing the name at the end. I posted the requirements and both java classes.

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");//Print title of rooster and quizzes System.out.println("");//Print blank space generateStuList(stuList);//Generate the array list StudentsQuiz stQuiz = stuList.get(0); // Storing the returned object by stuList.get(0) in stQuiz object of type StudentsQuiz as initially nIndex was zero when this line was getting printed repeatedly System.out.println("Students in Class: " + stQuiz.getNumberStudents());// Printing count of students just once System.out.println("");//Print blank space for (int nIndex = 0; nIndex < stuList.size(); nIndex++) { printStudentsQuiz(stuList.get(nIndex));//Initilize the for loop for list }//End of for loop Scanner input = new Scanner(System.in);//Reads info from user System.out.print("Please enter the last name of a specific student "); String sSpecificStudent = input.next().toUpperCase(); boolean bPrint = false; for (int nIndex = 0; nIndex < stuList.size(); nIndex++) { if (stuList.get(nIndex).getLastName()==sSpecificStudent){ printStudentsQuiz(stuList.get(nIndex)); bPrint= true; } } if (bPrint ==false) { System.out.println("No student with name " + sSpecificStudent + "found"); } }//End main method public static void printStudentsQuiz(StudentsQuiz myStudentsQuiz){ System.out.println("Student Name: "+ myStudentsQuiz.getFirstName() + " " + myStudentsQuiz.sLastName.toUpperCase());//Print out first and last name of students from list System.out.println("Quiz Average: "+ myStudentsQuiz.calculateQuizAverage());//Print out quiz averages for each student System.out.println("");//Print blank space }//End printStudentsQuiz method public static void generateStuList(ArrayList list) throws FileNotFoundException { //Read input from file String sFileName = "Students.txt"; String sInputLine = ""; File fileToOpen = new File(sFileName); //Creating wrapper class for the file name and its directory path Scanner inputFile = new Scanner(fileToOpen);//Creating scanner object for reading inputs String[] saTokens = null; //Initialize the while loop 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 and read all lines from the file }//End generateStuList method }//End of StudentsQuiz2 class

public class StudentsQuiz { //This class stores information about the student and quiz grades

//Declare class attributes private String sFirstName = ""; //First name of student String sLastName = ""; //Last name of student private int nQuiz1 = 0; //Grade for Quiz 1 private int nQuiz2 = 0; //Grade for Quiz 2 private int nQuiz3 = 0; //Grade for Quiz 3 private static int nNumberStudents = 0; //Number of students //Declare constants public static final int QUIZZES = 3; //Number of quiz grades //Default constructor for Student public StudentsQuiz() { //Update number of students created nNumberStudents++; } //end default constructor //Overloaded constructor for Student public StudentsQuiz(String sFName, String sLName, int nQ1, int nQ2, int nQ3) { //Assign parameter values to class attributes sFirstName = sFName; sLastName = sLName; nQuiz1 = nQ1; nQuiz2 = nQ2; nQuiz3 = nQ3; //Update number of students created nNumberStudents++; } //end overloaded constructor

//Accessor for First Name public String getFirstName() { return sFirstName; } //end accessor for First Name

//Mutator for First Name public void setFirstName(String sFstName) { sFirstName = sFstName; } //end mutator for First Name

//Accessor for Last Name public String getLastName() { return sLastName; } //end accessor for Last Name

//Mutator for Last Name public void setLastName(String sLstName) { sLastName = sLstName; } //end mutator for Last Name

//Accessor for Quiz 1 grade public int getQuiz1() { return nQuiz1; } //end accessor for Quiz 1

//Mutator for Quiz 1 grade public void setQuiz1(int nQz1) { nQuiz1 = nQz1; } //end mutator for Quiz 1

//Accessor for Quiz 2 grade public int getQuiz2() { return nQuiz2; } //end accessor for Quiz 2

//Mutator for Quiz 2 grade public void setQuiz2(int nQz2) { nQuiz2 = nQz2; } //end mutator for Quiz 2

//Accessor for Quiz 3 grade public int getQuiz3() { return nQuiz3; } //end accessor for Quiz 3

//Mutator for Quiz 3 grade public void setQuiz3(int nQz3) { nQuiz3 = nQz3; } //end mutator for Quiz 3 //Accessor for number of students public static int getNumberStudents() { return nNumberStudents; } //end accessor for number of students //Calculates the average of the three quiz grades for the student public double calculateQuizAverage() { double dAverage = 0.0; //Local variable to store quiz average //Calculate quiz average dAverage = (nQuiz1 + nQuiz2 + nQuiz3)/QUIZZES; return dAverage; } //end method calculateQuizAverage } //end class StudentsQuiz

Because there are several different things your program might do depending upon what the user enters, please refer to the examples below to use to test your program. Run your final program one time for each scenario to make sure that you get the expected output.

Be sure to format the output of your program so that it follows what is included in the examples. Remember, in all examples bold items are entered by the user when the program runs (and therefore can change each time the program runs).

Scenario 1: User searches for a student who exists. STUDENT ROSTER AND QUIZ AVERAGES

 Students in class: 10 
 Student Name: Leann ROSENBERRY Quiz average: 85.0 
 Student Name: Gia WALCK Quiz average: 83.0 
 Student Name: Archie SELLS Quiz average: 78.0 
 Student Name: Giuseppe DIMARTINO Quiz average: 73.0 
 Student Name: Lizabeth GOAD Quiz average: 79.0 
 Student Name: Paul ELLINGTON Quiz average: 76.0 
 Student Name: Eusebia TONGUE Quiz average: 79.0 
 Student Name: Drew BUCHWALD Quiz average: 73.0 
 Student Name: Lyndsey PACK Quiz average: 66.0 
 Student Name: Arica BARRETT Quiz average: 69.0 

Please enter the last name of a specific student: buchwald Student Name: Drew BUCHWALD Quiz average: 73.0

1

Scenario 2: User searches for a student who does not exist. STUDENT ROSTER AND QUIZ AVERAGES Students in class: 10 Student Name: Leann ROSENBERRY

 Quiz average: 85.0 
 Student Name: Gia WALCK Quiz average: 83.0 
 Student Name: Archie SELLS Quiz average: 78.0 
 Student Name: Giuseppe DIMARTINO Quiz average: 73.0 
 Student Name: Lizabeth GOAD Quiz average: 79.0 
 Student Name: Paul ELLINGTON Quiz average: 76.0 
 Student Name: Eusebia TONGUE Quiz average: 79.0 
 Student Name: Drew BUCHWALD Quiz average: 73.0 
 Student Name: Lyndsey PACK Quiz average: 66.0 
 Student Name: Arica BARRETT Quiz average: 69.0 

Please enter the last name of a specific student: Smith No student with name Smith found.

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

Oracle Database Administration The Essential Reference

Authors: Brian Laskey, David Kreines

1st Edition

1565925165, 978-1565925168

More Books

Students also viewed these Databases questions

Question

=+ (b) Show that X ,, - p X.

Answered: 1 week ago