473,399 Members | 2,478 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Java code problem

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++) {
System.out.println(
"Student number "+
students[p].getNo() +
" has name of " +
students[p].getName()
);
}
}
}



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 TestProgram_four.java:15: 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);
setSubject(aSubject);
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
setName(aName);
setLecturer(aLecturer);
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
1 1671
r035198x
13,262 8TB
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

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

Similar topics

133
by: Gaurav | last post by:
http://www.sys-con.com/story/print.cfm?storyid=45250 Any comments? Thanks Gaurav
2
by: Kent Lewandowski | last post by:
hi all, Recently I wrote some stored procedures using java jdbc code (admittedly my first stab) and then tried to implement the same within java packages (for code reuse). I encountered...
2
by: Michael | last post by:
Running DB2 v7 UDB ("DB2 v7.1.0.93", "n031208" and "WR21333") on Windows XP, I am unable to find out why the "Build for Debug" option within Stored Procedure Builder is not enabled on Java stored...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
6
by: Rhino | last post by:
I'm trying to debug a simple Java UDF written in the DB2General style within Eclipse. I'm getting a java.lang.UnsatisfiedLinkError when I execute the set() method in the UDF. I know that the...
458
by: wellstone9912 | last post by:
Java programmers seem to always be whining about how confusing and overly complex C++ appears to them. I would like to introduce an explanation for this. Is it possible that Java programmers...
3
by: akmkat | last post by:
Hi all, I am in a great problem. I am trying to implement a multithreaded server using java, first look at the code... /*------- Main Server (server.java)--------------*/ import java.io.* ;...
14
by: mlw | last post by:
Do not take anything about this, it is not a flame or troll, while I'm not new to Java I favor C++. However, I may need to use it in a contract position, and am concerned that the restrictions it...
1
by: amgupta8 | last post by:
Note: This problem occurred when I updated the JDK from 1.3.1 to 1.4.1 or 1.4.2. Nothing else was changed in the code, other than updating the JDK on the database server (dbm cfg parm jdk_path) and...
5
by: xirowei | last post by:
public class Result { private int countA = 0; private int countB = 0; private int statement; private boolean statusA = false; private boolean statusB = false; private int arrayA = new...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.