By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,911 Members | 1,222 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,911 IT Pros & Developers. It's quick & easy.

Java code problem

P: 2
Java problem

I need to generate the following output with a TestProgram.
Lecturer 65374 has 3 students:
Student number 1 has name of Amanda
Student number 2 has name of Patrick
Student number 3 has name of Jay

The Student and Lecturer classes are below.
Meanwhile, here is my attempetd test program:
public class TestProgram_four {

public static void main(String args[])
// create an array to hold three student references
Student students[] = new Student[3];
students[0]= new Student (1,"Amanda",65374);
students[1]= new Student (2,"Patrick",65374);
students[2]= new Student (3,"Jay",65374);

// retieve and display attribute values
for (int p=0; p<students.length; p++) {
"Student number "+
students[p].getNo() +
" has name of " +

Below are the Lecturer and Student scripts for which I need to create a TestProgram:

But first here is my attempt at the TestProgram. I am getting three error messages saying cannot resolve symbol
symbol : constructor Student (int,java.lang.String,int)
location: class Student
students[0]= new Student (1, "Susan", 65374);
There are other two error similar to above for Patrick and Jay

Code: ( java )
import java.util.*;
public class Lecturer // Lecturer class to illustrate 1 to many association with Student
{ // attributes........................................ ........(iii)
private int id;
private String subject;
private Vector students; // implement student association with Vector class
private Lecturer(int anId, String aSubject) // constructor
{ setId(anId);
students = new Vector(10); //start with Vector for 10 students
} //.................................................. .....(iv)
public void addStudentToLecturer(Student aStudent) // custom method addStudentToLecturer
{ students.addElement(aStudent); //........................(ii)
aStudent.setLecturer(this); // connect student to lecturer (1..1)
public Vector getStudents() // custom method to return vector of students.......(i)
{ return students;}
public void setId(int anId) // set accessor methods
{ id = anId;}
public void setSubject(String aSubject)
{ subject = aSubject;}
public int getId() // get accessor methods
{ return id;}
public String getSubject()
{ return subject;}

public class Student // Student with reference variable and accessors
{ private int no; //attributes
private String name;
private Lecturer lecturer;
public Student(int aNo, String aName, Lecturer aLecturer) //constructor with 2 parameters plus lecturer reference
{ setNo(aNo); //invoke accessors to populate attributes
lecturer.addStudentToLecturer(this); //tell lecturer to associate with this student
public void setNo(int aNo) //set accessor methods
{ no = aNo;}
public void setName(String aName)
{ name = aName;}
public void setLecturer(Lecturer aLecturer)
{ lecturer = aLecturer;}
public int getNo() //get accessor methods
{ return no;}
public String getName()
{ return name;}
public Lecturer getLecturer()
{ return lecturer;}
Jun 21 '07 #1
Share this Question
Share on Google+
1 Reply

P: 13,264
1.) Code tags code tags code tags code tags code tags
2.) Look at each error one by one and fix the program as per its suggestion. The error messages really give you very good hints.
Jun 21 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.