Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Displaying Class Info in another Class  RSS feed

 
Wayne Styles
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I am new to Java and just learning.
I have set up 2 classes students and lecturers.
I have now set up another class called college.
I want college to display the information contained in students and lecturers in the class college.

Q
Can I do this
Q
How

Thanks in advanced
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, could you show us bits of what you have now? For instance, do you have code to construct a bunch of Student and Lecture objects? I'm imagining we need a new top level bit of code something like:

If you don't have createSomeWhatever() written yet, we can start there. Let us know just where you're stuck.
 
Wayne Styles
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Stan
Ok
Here is the code for both classes.
package college;

/**
* Title:
* Description:
* Copyright: Copyright (c) 2006
* Company:
* @author
* @version 1.0
*/

public class Lecturer {
String name;
String staffID;
String subjectID;

public Lecturer(String newName, String newStaffID, String newSubjectID)
{
name=newName;
staffID=newStaffID;
subjectID=newSubjectID;
}
public String getName (){
return name;
}
public void changeStaffID (String newstaffID){
staffID=newstaffID;
}
public void changeSubjectID (String newSubjectID){
subjectID=newSubjectID;
}
public String getstaffID(){
return staffID;
}
public String getSubjectID(){
return subjectID;
}
}
Above is the lecturer class
Below the student class
package college;

/**
* Title:
* Description:
* Copyright: Copyright (c) 2006
* Company:
* @author
* @version 1.0
*/

public class Student {
String name;
String studID;
String courseID;

public Student(String newName, String newStudID, String newCourseID)
{
name=newName;
studID=newStudID;
courseID=newCourseID;
}
public void changeName (String newName){
name=newName;
}
public void changeStudID (String newstudID){
studID=newstudID;
}
public void changeCourseID (String newCourseID){
courseID=newCourseID;
}
public String getName(){
return name;
}
public String getstudID(){
return studID;
}
public String getCourseID(){
return courseID;
}
}
I now have a class called mainclassmethod. What I would like to do is now display the information from student class AND lecturer class in the mainmethod class!!!
Am I being too ambitious?
 
Wayne Styles
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can anyone HELP please
 
Rusty Shackleford
Ranch Hand
Posts: 490
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you look at those links I gave you in one of your other threads?

Look up the toString method or you can just use the acessor methods you already have, but is not as efficient.
[ August 21, 2006: Message edited by: Rusty Shackleford ]
 
Wayne Styles
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I went through pages of tutorials, but it just gets to be confusing after a while and if you cant follow some of the info, I get mixed up.
I want to spend learning Java, but any help on this would be great as I will be able to follow what is going on.
Thanks
 
Rusty Shackleford
Ranch Hand
Posts: 490
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pointing you to toString() isn't enough help for this problem?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!