I am have trouble compiling my code. Student and StudentList First, implement two simple classes:
View the step-by-step solution to:

Question

I am have trouble compiling my code.



Here is what I am trying to

acheive == I have also attached my current codes


Phase 1: Student and StudentList


First, implement two simple classes: a Student class and a StudentList class


The Student class should have:

1)  Three instance variables: the student's first name (a String), last name (a String) and student number (an int)

2)  A constructor that has three parameters, in the above order, which are used to initialize the three instance variables.

3) A standard toString method, which returns a String containing the student's last and first names separated by a comma, and student number in between parentheses (as shown in the output below).

4)  An equals method that checks if two Students are equal. Two students are equal if they have the same first name, last name and student number.

 


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) 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) 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).

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

You can test your classes using the supplied test program TestPhase1.java. You should get the output shown below.

======my code for phase 1 ====


public class Student

{

 

 private String firstName;

 private String lastName;

 private int studentNum;

 

 public Student( String firstName, String lastName, int studentNum)

 {

 this.firstName = firstName;

 this.lastName = lastName;

 this.studentNum = studentNum;

  

 }  

   

  public String toString()

 {

   return (lastName + "," + firstName + "(" + studentNum + ")");

 }

   

  public boolean equals(Student student)

 {

 return firstName.equals(student.firstName) && lastName.equals(student.lastName) && studentNum == student.studentNum;

 }

}

----------------------------------

class StudentList{


  private Student[] students;

  private int currentNum;

  private int MAX_SIZE;


 public StudentList(int MAX_SIZE)

 {

 students = new Student[MAX_SIZE];

 currentNum = 0;

 this.MAX_SIZE=MAX_SIZE;

 }


 public boolean contains(Student s)

 {

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

   if(students[i].equals(s))

    return true;

 }

  return false;

 }


 public boolean addStudent(Student s)

 { {

   if(currentNum==MAX_SIZE)

    return false;

 }

    students[currentNum++]=s;

    return true; 

    

 }



 public String toString()

 {

 String list = "";

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

 {

  list += (students[i]+"n");

 }

 return list;



 }

}







Phase 2: Course and CourseList

Next, implement the Course class, and a CourseList.

 

The Course class should have:

1)   A class constant: the maximum size of the wait list (you can set it to 100).

·        Five instance variables: the title of the course (a String), the short title of the course (a String - e.g. COMP1020), the maximum class size (an int), a class list (a StudentList) and a wait list (a StudentList).

2)  A constructor that accepts three parameters, the title, short title and maximum class size. The two StudentLists should also be instantiated by the constructors.

3)   A method register(Student) that registers the Student to the appropriate list, if possible, using the rules described here:

o   if the student is already in the class list, nothing is to be done, and the method should print "The student [student description] is already registered to [course short title]!"

o   if the student is not in the class list, and space is available, the method adds the student to the class list and prints: "The student [student description] has been registered successfully to [course short title]." This method also adds the course to the course list of the student (see Changes to Student class below).

o   if the class list is full, then the method tries to add the student to the wait list

o   if the student is already on the wait list, nothing is to be done and the method should print "The student [student description] is already on the wait list for [course short title]!"

o   if the student is not on the wait list and space is available, the method adds the student to the wait list and prints: "The student [student description] has been placed on the wait list for [course short title]."


o   if the wait list is full, nothing is to be done and the method prints "The wait list is full for [course short title]!"

4)  A getTitles method, that returns a String containing the course short title followed by a dash and the course title.

5)  A toString method that returns a String containing the course short title followed by a dash and the course title on the first line. On the following lines, the class list and wait list are printed (see example below).


Then, implement a CourseList class. This class should have:

1)  A class constant: the maximum number of courses a student can take (set it to 100).

2)  Two instance variables: an array of Courses, and the current number of courses in the list (an int)

3) A constructor that has no parameters, which initializes the instance variables (the CourseList should be empty when created).

4) A method contains(Course) that returns true if the course is already in the list, false otherwise.

5)  An addCourse(Course) method (void) that adds the Course to the list.

6) a getAllTitles method that calls the getTitles method for each Course of the list, and builds a String

representation of all the courses on the list, one Course per line.

7)   A toString method that returns a String containing the full String representation (titles, class list and wait list) of all Courses in the list (as shown in the example below).


Changes to Student class:

·        Add an additional instance variable: a CourseList, containing the list of all courses the student is registered to (fully registered, not on the wait list).

·        The constructor should instantiate the above instance variable (empty CourseList).

·        A method addCourse(Course), that adds the Course to the CourseList. You may assume that it will never get full.

·        A method getCourseListString, that returns a String containing "Student [student description] is registered to:" followed on the next lines by the list of course titles, using the getAllTitles method of the CourseList class.


You can test your class with TestPhase2.java.


=====================my code for Phase 2 =========

public class Course

{

 //Class constant

 private static final int MAX_SIZE_WAIT = 100;

 

 // instances 

 private String title;

 private String shortTitle;

 private int classSize;

 private StudentList classList;

 private StudentList waitList;

 

 public Course( String title, String shortTitle, int classSize)

 {

 this.title = title;

 this.shortTitle = shortTitle;

 this.classSize = classSize;

 classList = new StudentList();

 waitList = new StudentList();

 }  

 

 public register(Student s)

  {

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

 {

   if(students[i].equals(s))

   return " The Student " + Student.toString() + " is already registered to " + shortTitle;    

 }

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

   {

    if(!students[i].equals(s)) && Student.currentNum()!= classSize)

    return //// add student to class if the class is not full 

   }

    

  }


 public String getTitles ()

 {

  return shortTitle + " - " + title;

 }

  

 public String toString()

 {

  return shortTitle + " - " + title + "n" + classList + waitList; 

 }

}


---------------------------------------------------------------



public class CourseList

{

//Class constant

 private static final int MAX_NUM_COURS = 100;

 private Course[] courses;

 private int currentNumCour;

  

 public CourseList()

 {

 }

  

 public contains (Course p)

 {

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

  {

   if(courses[i].equals(p))

    return true;

  }

  return false;

 }

  

  

 public void addCourse(Course p)

 {

  courses.addCourse(p);

 }

  

  

 public String getAllTitles()

 {

  return courses.getTitles() + "n" ;

 }

  

 private CourseList listOfCour;

  

}


Phase 3: Withdrawing from a Course

Next implement a withdraw(Student) method in the Course class, which will withdraw the Student from the class list, if the Student is on the class list, or withdraw the Student from the wait list, if the Student is on the wait list, or do nothing if the Student is not in any of the lists.

·        The method must print:

o   "The student [student description] has been withdrawn from [course short title]." if the student was on the class list.

o   "The student [student description] has been withdrawn from the wait list of [course short title]." if the student was on the wait list.

o   "The student [student description] is not on any list of [course short title]." otherwise.

·        If the Student was on the class list, the method must also remove the Course from the Student's CourseList.

·        If the Student was on the class list, and there is at least one Student on the wait list, the first Student on the wait list must be registered to the class list (and removed from the wait list).

·        When removing a Student from a class/wait list, or removing a course from a CourseList, you must fill in the gap by shifting up all the following Students/Courses. Also, don't forget to update the counter of the current number of students or current number of courses.

·        Important: to fully complete Phase 3, following the instructions above, you will need to add other methods to other classes (while maintaining encapsulation - every object is responsible for modifying its own instance variables).



=========

Recently Asked Questions

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
Ask Expert Tutors You can ask 0 bonus questions You can ask 0 questions (0 expire soon) You can ask 0 questions (will expire )
Answers in as fast as 15 minutes