Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Student class: Instance variables name id Constructors: Default constructor Constructor that has id and name passed to the constructor Methods: Accessors int getID( ) String

Student class:

  • Instance variables
    • name
    • id
  • Constructors:
    • Default constructor
    • Constructor that has id and name passed to the constructor
  • Methods:
    • Accessors
      • int getID( )
      • String getName( )

Class Roster: This class will implement the functionality of all roster for school.

  • Instance Variables
    • a final int MAX_NUM representing the maximum number of students allowed on the roster
    • an ArrayList storing students
  • Constructors
    • a default constructor should initialize the list to empty strings
    • a single parameter constructor that takes an ArrayList
    • Both constructors should initialize the instance variables
  • Methods
    • Accessors
      • boolean containsStudent(String studentName) //@returns true if studentName is in roster
      • String retrieveById(int id) //@ returns Student name associated with id
      • int retrieveByName(String Student) //@returns id associated with String Student
    • Mutators:
      • boolean addStudent(String studentName, int studentId) ;//adds student name and id to end of roster
        • This method should not allow a student to be added if the name or the studentId is already in the roster. Also, make sure that the total number of students does not exceed MAX_NUM. Hint: Make user of the containsStudent() method
      • boolean removeStudent(int id) // removes student from roster based on id. Make sure that you maintain the integrity of the parallel ArrayLists.
      • boolean removeStudent(String name) //removes student based on name. Make sure that you maintain the integrity of the parallel ArrayLists.

Grading rubric

constructors

1 single parameter

1 default

-> initializes both Array Lists

-> initalize MAX_NUM

2 boolean containsStudent(String studentName)

//@returns true if studentName is in roster

2 String retrieveById(int id)

//@ returns Student name associated with id

2 int retrieveByName(String Student)

//@returns id associated with String Student

1 boolean addStudent(String studentName, int studentId) ;

//adds student name and id to end of roster

This method should not allow a student to be added if the name or the studentId is already in the roster or allow the total number of students to exceed MAX_NUM. Hint: Make user of the containsStudent() method

//The next 2 methods must maintain the integrity of the parallel ArrayLists. If you remove from 1 then remove the element in the other ArrayList associated with the first list's elements. In other words, if you remove a student based on his or her name, make sure that you also remove his or her id from the other ArrayList.

3 boolean removeStudent(int id)

// removes student from roster based on id

3 boolean removeStudent(String name)

//removes student based on name

Total points 15

Testing data:

Student names: Jack, Jane, Janet, Jasmin

Student IDs: 1005, 1007, 1009, 1011

output

Add: Jessie, 1017

Remove: Jane

output

Remove: 1011

Retrieve ID: 1011

Retrieve student: Jessie

Output

Add Jessie, 1017, output if adding is successful

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

More Books

Students also viewed these Databases questions

Question

d. How were you expected to contribute to family life?

Answered: 1 week ago