Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi, I will post the sorter and search programing. Thank you. import java.util.ArrayList; /** * The Roster class encapsulates an ArrayList object named mStudentList which

Hi,

I will post the sorter and search programing.

Thank you.

import java.util.ArrayList;

/** * The Roster class encapsulates an ArrayList object named mStudentList which stores the * information for each student that was read from "gradebook.txt" when the app started. * */ public class Roster {

/** * Declare mStudentList as ArrayList */ private ArrayList mStudentList ;

/** * Roster() * PSEUDOCODE: * method Roster() * -- Note that mStudentList was already declared so we do not need to declare it here. * -- What we need to do here is create the ArrayList object that mStudentList * -- will refer to. * create an ArrayList object and then pass that object as the argument to * setStudentList() to make mStudentList refer to the ArrayList * end Roster */ public Roster(){ mStudentList =new ArrayList(); setStudentList(mStudentList); }

/** * addStudent() * * Adds pstudent to the ArrayList * * PSEUDOCODE: * method addStudent(pStudent : Student) : void * add (will append) pStudent to mStudentList * end method */ public void addStudent(Student pStudent){ mStudentList.add(pStudent); }

/** * getStudent() * * Searches mStudentList for a Student with pLastName. * * PSEUDOCODE: * method getStudent(pLastName : String) : Student * -- Get the index of the student in the student list * index = call Searcher.search(getStudentList(), pLastName) * -- If index is -1 then no student with that last name could be found so we return * -- null. Otherwise, we get the Student from the student list at the index and return * -- the Student. * if index == -1 then return null * else return the Student object in getStudentList() at index 'index' * end getStudent */ public Student getStudent(String pLastName){ int index = Seacher.search(getStudentList(), pLastName);

if(index ==-1){ return null; } return mStudentList.get(index); }

/** * getStudentList() * * Accessor method for mStudentList. * * Note: it is extremely sleazy to provide public access to the entire private student list * (mStudentList) in this way because it gives whoever calls this method the ability to * modify any Student in the roster. It would be better to have the Roster class implement an * iterator that would permit other objects to iterate over the elements of the list, but in an * effort to keep the project as simple as possible, I am taking the sleazy route. * * If you are so inclined, by all means, implement the iterator. */ public ArrayList getStudentList() { return mStudentList; }

/** * setStudentList() * * Mutator method for mStudentList. */ private void setStudentList(ArrayList pStudentList) { mStudentList = pStudentList; }

/** * sortRoster() * Called to sort the roster by last name. * * PSEUDOCODE: * method sortRoster() * -- Note that all of the methods in Sorter are class methods, so we call the sort() * -- method on the class Sorter. * call Sorter.sort() passing the list of students returned from getStudentList() * end sortRoster */ public void sortRoster() { Sorter.sort(mStudentList); }

/** * Returns a String representation of this Roster. toString() methods are very handy for * debugging because given access to a Roster object, say named roster, then you can print * the entire roster in one statement: System.out.println(roster); */ @Override public String toString() { String result = ""; for (Student student : getStudentList()) { result += student + " "; } return result;

} }

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 Theory Icdt 99 7th International Conference Jerusalem Israel January 10 12 1999 Proceedings Lncs 1540

Authors: Catriel Beeri ,Peter Buneman

1st Edition

3540654526, 978-3540654520

More Books

Students also viewed these Databases questions

Question

Describe the patterns of business communication.

Answered: 1 week ago

Question

3. Provide two explanations for the effects of mass media

Answered: 1 week ago