title: Java - Modifying a class to compute total number of objects created
body: <p>Currently, I'm working on a small practice beginner program with 3 classes, that I'm trying to modify.  I want to modify class Student so that it computes the total number of objects created, and I want to modify class Course so that it includes an array of the Student class.  Here is what I have so far; any assistance would be appreciated.  I'm sure its obvious, and I'm just being dense:</p>
  
  <p>Class Course:</p>
  
  <pre><code>public class Course {
    private String courseName;
    private Student[]
    students = new Student[100];
    private int numberOfStudents;
  
    public Course(String courseName) {
      this.courseName = courseName;
    }
  
    public void addStudent(String[] Student) {
      Student[numberOfStudents] = students[];
      numberOfStudents++;
    }
  
    public Student[] getStudents() {
      return students;
    }
  
    public int getNumberOfStudents() {
      return numberOfStudents;
    }  
  
    public String getCourseName() {
      return courseName;
    }  
  
    public void dropStudent(String student) {
  
    }
  }
  </code></pre>
  
  <p>Class Student:</p>
  
  <pre><code>public class Student {
  private int id;
  private String name;
  private java.util.Date dateCreated;
  
  public Student(int ssn, String newName) {
      id = ssn;
      name = newName;
      dateCreated = new java.util.Date();
  }
  
  public int getID() {
      return id; 
  }
  
  public String getName() {
      return name;
  }
  
  public java.util.Date getDateCreated() {
      return dateCreated;
  }
  }
  </code></pre>
  
  <p>And the driver class, class TestCourse:</p>
  
  <pre><code>public class TestCourse {
    public static void main(String[] args) {
       Course course1 = new Course("Data Structures");
       Course course2 = new Course("Database Systems");
  
  course1.addStudent("Peter Jones",);
  course1.addStudent("Brian Smith");
  course1.addStudent("Anne Kennedy");
  
  course2.addStudent("Peter Jones");
  course2.addStudent("Steve Smith");
  
  System.out.println("Number of students in " +course1.getCourseName() + ":  "
    + course1.getNumberOfStudents());
  String[] students = course1.getStudents();
  for (int i = 0; i &lt; course1.getNumberOfStudents(); i++)
    System.out.print(students[i] + ", ");
  
  System.out.println();
  
  System.out.print("Number of students in " +course2.getCourseName() +":  "
    + course2.getNumberOfStudents());
  
  System.out.println();
  
  String[] students1 = course2.getStudents();
  for (int i = 0; i &lt; course2.getNumberOfStudents(); i++)
    System.out.print(students1[i] + ", ");
    }
  }
  </code></pre>