Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Instructions:create a new method (in the GradeBook class) that finds a Student i

ID: 3534686 • Letter: I

Question

Instructions:create a new method (in the GradeBook class) that finds a Student in the roster. This method (to be named find) should take an ID and return the Student object corresponding to that ID. If there is no student object corresponding to that ID in the class, it should return null. Test this method using GradeBookMain. Your main should read in the students, print the roster and then ask the user whose data (to be indicated by ID) they want to see. You should then look up that student and print his or her data. If the student is not there, you (and not the Java system) are to print a friendly error message

In GradeBook.java I have: <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

public String find(String id) {

Student st= new Student();

String stud;

for(int i=0;i<roster.size();i++)

roster.get(i);

if(id.equals(st.getID())){

stud = st.toString();

}

else{

stud=null;

System.out.println("The ID you typed is not valid for this class. Please try a different one.");

}

return stud;

}

In GradeBookMain:

//scanner for find method

System.out.println("Which student's data would you like to see? Print their ID here: ");

Scanner sc = new Scanner(System.in);

String id = sc.next();

System.out.println(gb.find(id));

And in student class:

privateString ID;

public String getID() {

return ID;

}

Thank you!

Explanation / Answer

Please rate with 5 stars :)


You are missing a brace after the statement

for(int i=0;i<roster.size();i++)


The following lines have to be inside the for loop


That should do it.


Cheers!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote