Help setting up a Class

P

PB

i have a class called school.java and i cant figure out how to construct
another class called course.java that adds 2 people to a course. Can anyone
help me out on how to set up constructors and such. Here is school.java

import java.text.DecimalFormat;

public class School
{
//-----------------------------------------------------------------
// Creates some Student objects, adds them to a course, and
// prints them.
//-----------------------------------------------------------------
public static void main (String[] args)
{
Address school = new Address ("800 Lancaster Ave.", "Villanova",
"PA", 19085);

Address jHome = new Address ("21 Jump Street", "Lynchburg",
"VA", 24551);
Student2 john = new Student2 ("John", "Smith", jHome, school,
75, 88, 78);

Address mHome = new Address ("123 Main Street", "Euclid", "OH",
44132);
Student2 marsha = new Student2 ("Marsha", "Jones", mHome, school,
100, 98, 94);

Course zoology = new Course("Zoology 101");
zoology.addStudent(john);
zoology.addStudent(marsha);

zoology.roll();

DecimalFormat formatter = new DecimalFormat("0.0#");
System.out.println();
System.out.println ("-------------------------------------");
System.out.print ("Overall Test Average: ");
System.out.println (formatter.format(zoology.average()));
}
}
 
K

kevinc

What you have is the correct way to do it.
If you want a ctor that takes N number of students.
You would probably want to create a Course ctor that takes a collection

public class Course {

public Course(List aCollectionOfStudents){

studentColl.addAll(aCollOfStudents);
}


private List studentColl = new ArrayList();

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,431
Messages
2,571,678
Members
48,796
Latest member
Greg L.

Latest Threads

Top