View the step-by-step solution to:

Question

Please assist with my code below. I dont know what I am doing wrong.

/>

I am trying to produce the below


The StudentList class should have:

1) Three instance variables: an array of Students, the maximum size of the array (an int) and the current number of students in the array (an int)

2)  A constructor that takes one parameter: the maximum size of the array. The other instance variables must be initialized in the constructor (assume that the StudentList will be empty when constructed).

3)  A method contains(Student) that checks if the student is already in the list and returns a boolean (true if in the list or false otherwise).

4) A method addStudent that has a parameter of type Student, adds the Student to the list only if there is enough space. This method returns a boolean (true if the student was added and false otherwise).

·        A toString method which returns a String containing all the Students in the list, one Student per line (as shown below).

--------------------------------------------------------------------------------My code currently---------------------------

public class StudentList

{

  

 private String [] students;

 private int currentNum;

 private static final int MAX_SIZE = 1000;

 

 

 public StudentList()

 {

 

  students = new Student[MAX_SIZE];

  currentNum = 0;

 }

  

 

 public boolean contains(Student s)

 {

  if (student.contains(student)){

  return true;

  }

  else{

  return false;

  }

 }

  

 public boolean addStudent(Student s)

 {

  for (int i = 0; i < currentNum; i++)

 }

  return true; 

  else

  return false;

  

  

 }

 

  

 public String toString()

 {

  String list = "";

  for (int i = 0; i < currentNum ; i++);

  {

   list += students[i];

  }

  return list;

 }

  

}

Top Answer

Sign up to view the full answer

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question