473,750 Members | 2,190 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Java code problem

2 New Member
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_fou r {

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",653 74);
students[1]= new Student (2,"Patrick",65 374);
students[2]= new Student (3,"Jay",65374) ;

// retieve and display attribute values
for (int p=0; p<students.leng th; p++) {
System.out.prin tln(
"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_fou r.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(aSub ject);
students = new Vector(10); //start with Vector for 10 students
} //............... ............... ............... ..... .....(iv)
public void addStudentToLec turer(Student aStudent) // custom method addStudentToLec turer
{ students.addEle ment(aStudent); //............... .........(ii)
aStudent.setLec turer(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(Stri ng 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(aLe cturer);
lecturer.addStu dentToLecturer( 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(Lec turer 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 1696
r035198x
13,262 MVP
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
8568
by: Gaurav | last post by:
http://www.sys-con.com/story/print.cfm?storyid=45250 Any comments? Thanks Gaurav
2
9244
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 problems doing this. I wanted to implemented a generic "Helper" class like this: /** * Helper
2
3149
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 procedures. It is enabled for SQL stored procedures. It is possible to "Build" and "Run" the Java SPs, it just isn't possible to click on the "Build for Debug" option. Thanks for any help in advance. Michael
1
9650
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 and I was wondering if anyone here would be able to give me some tips for young players such as myself, for learning the language. Is this the best Newsgroup for support with JAVA?
6
2438
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 UnsatisfiedLinkError has something to do with a DLL that is not visible but I'm not sure why I'm having the problem given that both db2java.zip and db2jcc.jar are visible on my classpath and each of them contain the COM.ibm.db2.app.UDF class with a...
458
21348
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 simply aren't smart enough to understand C++? This is not merely a whimsical hypothesis. Given my experience with Java programmers --- the code they write and the conversations they have --- Occam's Razor points to this explanation. For example,...
3
2642
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.* ; import java.net.* ; public class server {
14
5690
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 places on application code. Take, for instance, this C++ construct: class foo { char *m_name;
1
2974
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 recompiling/executing the code with 1.4.1 (deploying the newly compiled stored procedure code as well). This is the original exception that I got before I tried any code modifications: java.io.IOException: invalid offset/length at...
5
2521
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 int; <= the problem seem like happen at here? private int arrayB = new int; <= the problem seem like happen at here?
0
8999
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9575
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9394
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9338
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6803
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6080
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4712
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4885
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2223
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.