Results 1 to 3 of 3
- 05-21-2011, 02:18 AM #1
Member
- Join Date
- May 2011
- Posts
- 7
- Rep Power
- 0
Linked List implementation of various classes
I am relatively new to Java, and I am currently in a dead end on a program with no idea how to continue. Here is where I am at.
I implemented a typical singly linked list which contains multiple nodes of class "Student" (1 node per student). However, I need every student to be able to implement a class called "Courses" any amount of time. For example, 1 student in the linked list might have 4 courses (math, bio, phys,english) whereas another student in the linked list might have 23.
What data structure would be optimal for accessing different courses from different students? How would I tie both classes together in such a fashion?
Thanks in advance!
- 05-21-2011, 02:48 AM #2
What kind of "container" you put the items in would depend on how you want to access them.
Serially from the beginning: ArrayList
Randomly by name: Map
- 05-21-2011, 03:12 AM #3
Member
- Join Date
- May 2011
- Posts
- 2
- Rep Power
- 0
I agree with Norm, data structure will depend on how you will access "Courses". I think ArrayList is a better choice, but this is my personal opinion. Regarding your second question i think you can use something similar to that:
Class "Courses" here has only one method "showCourse()" that returns name of the course.Java Code:import java.util.*; public class Student { Student(String aName,String... args) { name=aName; cname=args; for(int i=0;i<cname.length;i++) { cour.add(new Courses(cname[i])); } } public void showAll() { for(int i=0;i<cname.length;i++) { System.out.println(cour.get(i).showCourses()); } } private String name; private String[] cname; private ArrayList<Courses> cour = new ArrayList<Courses>(); }Last edited by giggs; 05-21-2011 at 03:53 AM.
Similar Threads
-
How to access an element of a linked list inside another linked list?
By smtwtfs in forum New To JavaReplies: 4Last Post: 02-21-2011, 09:34 AM -
Linked list implementation using core java
By jhapranay in forum Advanced JavaReplies: 0Last Post: 02-03-2011, 03:15 PM -
Storing Mutiple Classes/Data Types in a Linked List
By Chronoattica in forum New To JavaReplies: 7Last Post: 12-28-2010, 10:03 PM -
Linked list inside a linked list
By viperlasson in forum New To JavaReplies: 5Last Post: 07-26-2010, 11:15 PM -
Question about linked implementation
By bdario1 in forum New To JavaReplies: 5Last Post: 04-23-2010, 11:00 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks