Results 1 to 9 of 9
  1. #1
    bkafroboy69 is offline Member
    Join Date
    Nov 2010
    Posts
    4
    Rep Power
    0

    Default Linked based project would like some help

    im posting my coding to see if anyone here can help me understand and debug my coding. ill be putting up the instructions on what i need to do

    The Course class
    A Course object should store the department, course number, and course title. It should have linked lists of prerequisites and "subsequents" (the courses for which this course is a prerequisite).

    The constructor should construct a course given a department, course number, and course title.

    There should be methods to add prerequisites and subsequents.

    There should be accessor methods for all the fields.

    The toString method should return a String with all the course information.

    You are free to implement other methods as needed to complete the project.

    Java Code:
    public class Course{
    	private String department,coursetitle;
    	private int coursenumber;
    	private LinkedList<String> prerequisites;
    	private LinkedList<String> subsequents;
    	
    	
    
    
    	public Course(String dep, int num, String title) {
    		department = dep;
    		coursenumber = num;
    		coursetitle = title;
    		prerequisites = new LinkedList<String>();
    		subsequents = new LinkedList<String>();
    	}
    
    	public String getDepartment() {
    		return department;
    	}
    
    	public void setDepartment(String department) {
    		this.department = department;
    	}
    
    
    	public int getCoursenumber() {
    		return coursenumber;
    	}
    
    	public void setCoursenumber(int coursenumber) {
    		this.coursenumber = coursenumber;
    	}
    
    	public String getCoursetitle() {
    		return coursetitle;
    	}
    
    	public void setCoursetitle(String coursetitle) {
    		this.coursetitle = coursetitle;
    	}
    
    	public void addPrerequisite(String department, String number) {
    		this.prerequisites.add(department + number);
    	}
    
    	public LinkedList<String> getPrerequisites() {
    		return prerequisites;
    	}
    
    
    	public void addSubsequent(Course course) {
    		this.subsequents.add(course.getDepartment() + course.getCoursenumber());
    	}
    
    	public LinkedList<String> getSubsequents() {
    		return subsequents;
    	}
    
    	public boolean equals(Object obj) {
    		if (this == obj) {
    			return true;
    		}
    		
    		if (!(obj instanceof Course)) {
    			return false;
    		}
    		Course course = (Course) obj;
    		
    		if (course.getCoursenumber() == this.getCoursenumber() &&
    			 course.getDepartment().equals(this.getDepartment())) {
    			return true;
    		}
    		return false;
    	}
    
    
    
    
    	public String toString() {
    		
    StringBuffer str = new StringBuffer();
    		
    		str.append(department + " ");
    		str.append(coursenumber);
    		if (coursetitle != null) {
    			str.append(" " + coursetitle);
    		}
    		if (!this.prerequisites.isEmpty()) {
    			str.append("\n\t\tPrereqs: " + this.prerequisites);
    		}
    		if (!this.subsequents.isEmpty()) {
    			str.append("\n\t\tSubsequents: " + this.subsequents);
    		}
    		return str.toString();
    
    	}
    
    
    
    
    
    
    
    
    }

    The CourseCatalog class
    Required Constructor:

    public CourseCatalog(String filename)

    Required Method:

    public String toString()

    This class should store a linked list of courses.

    The constructor should construct a course catalog given a file name. Example files are provided below. All the courses in the file should be constructed and should include all prerequisite and subsequent information.

    There should be methods to return a course given its name. It should have some flexibility, e.g., "CS 2123" or "cs2123" should result in the same course.

    The toString method should return a String describing all the courses.

    There should be some way to access or loop thru all the courses in the course catalog.

    You are free to implement other methods as needed to complete the project.

    Java Code:
    package courses;
    
    import java.io.BufferedReader;
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.util.Iterator;
    import java.util.LinkedList;
    
    
    
    public class CourseCatalog<T>{
    	 private BufferedReader read;
    	 private LinkedList<Course> catalog;
    
    
    
    	
    	public CourseCatalog(String filename) throws FileNotFoundException {
    		this.read = new BufferedReader(new FileReader(filename));
    		catalog = new LinkedList<Course>();
    	}
    
    	public LinkedList<Course> getCatalog() {
    		return this.catalog;
    	}
    
    	
    	
    	   
    	public String toString() {
    		Iterator<Course> itr = catalog.iterator();
    		StringBuffer str = new StringBuffer();
    		Course course = null;
    	
    		str.append("{\n");
    		while(itr.hasNext()) {
    			course = itr.next();
    			str.append("\n");
    			str.append(course);
    		}
    		str.append("}");
    		
    		return str.toString();
    
    	}
    }



    Java Code:
    package courses;
    
    public class CourseManager<T> {
    private T[] array;
    private int size;
    	
    	
    	public CourseManager(CourseCatalog catalog) {
    		array =(T[]) new Object();
    		size =0;
    	}
    	public String[] allowedCourses(){
    	/*
    	 * Returns courses that can be taken based on the 
    	 * course list. This should not include courses already on the 
    	 * course list. This should include courses that have no prerequisites,
    	 *  except for courses already on the course list. 
    	 */
    		if((String[]) array[size] != null);
    		
    		return null;
    	}
    	public boolean add(String courseName){
    	/*
    	 * Returns true if the course was successfully 
    	 * added to the list. Returns false if the course 
    	 * cannot be added. 
    	 */
    		if(size()<array.length){
    			array[size]=(T) courseName;
    			size++;
    			return true;
    		}else{
    		return false;
    		}
    	}
    	public boolean remove(String courseName){
    		
    	/*
    	 * Returns true if the course was successfully 
    	 * removed fron the list. Returns false if the 
    	 * course cannot be removed. 
    	 */
    		for(int i=0;i<size;i++){
    			if(courseName.equals(array[i])){
    				array[i]=array[size-1];
    				size--;
    				return true;
    			}else{
    				return false;
    				
    			}
    		}
    		return false;
    	}
    	public String[] getCourseList(){	
    	/*
    	 * Return the courses in the course list. 
    	 * The course list field in a CourseManager object should
    	 *  be a linked list of Course objects. This method should 
    	 *  return the courses as a String array. 
    	 */
    		
    		return (String[]) array[size];
    	}
    	public String[] getPrerequisites(String courseName){
    	/*
    	 * Returns the prerequisites of the given course. 
    	 */
    		
    		return getPrerequisites(courseName);
    	}
    	public String[] getSubsequents(String courseName){
    	/*
    	 * Returns the courses for which this course is a prerequisite. 
    	 */
    		return getSubsequents(courseName);
    	}
    	public String toString(){
    	/*
    	 * Returns a String with all courses in course list 
    	 */
    		return null;
    	}
    	String toString(String courseName){
    
    	/*
    	 * Returns verbose String description of the course. 
    	 */
    		return null;
    	}
    	public int size(){
    		return 0;
    		
    	}
    
    
    }
    Last edited by bkafroboy69; 11-03-2010 at 02:04 AM.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default

    And your problem is?

  3. #3
    bkafroboy69 is offline Member
    Join Date
    Nov 2010
    Posts
    4
    Rep Power
    0

    Default

    i just wanted to know if i did my project right and did what it asked of me in the instructions. i just want my work doubled checked

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default

    Oh...does it work?

    ...on first glance it seems reasonably laid out.

    That fulfils two of my main criteria for code.

  5. #5
    bkafroboy69 is offline Member
    Join Date
    Nov 2010
    Posts
    4
    Rep Power
    0

    Default

    it was working when i fisrt strarted working then when i run it all i get is a blank output so i wanted some help with my classes see if i did them right from the instructions

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default

    OK, well in the CourseCatalog constructor I suspect you should be taking the file supplied and reading it, adding the courses to your List. There's no need to actually hold onto the BufferedReader, you just need it in the constructor to read in the Courses. At the moment you aren't reading it so the List of Courses is empty.

    Also, in the print() method of the CourseCatalog class the declaration of course ought to be inside the loop since you aren't using it outside the loop at all. But that's a style/standard thing and won't actually stop your code from working.

  7. #7
    bkafroboy69 is offline Member
    Join Date
    Nov 2010
    Posts
    4
    Rep Power
    0

    Default

    how do i make it it read my file then?

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default

    Look at the Java IO tutorial on Oracle.
    I haven't got the link handy.
    That has some file reading examples (and explanations).

  9. #9
    chyrl is offline Senior Member
    Join Date
    Mar 2010
    Location
    Manila, Philippines
    Posts
    257
    Rep Power
    5

    Default

    This is strange, why not use the OOP pattern? Like,
    Java Code:
    LinkListed<Course> prerequisites, subsequents
    Hint:
    Also, rather use to appropriate beans rather than using a String collections for LinkListed classes, though it is also similar, but it might lessen the lines of codes.
    Every project, package, class, method, variable, syntax, algorithm, etc.
    are registered in my memory bank. Thanks to this thread.

Similar Threads

  1. i need an example of JSR179 ((Location based Ser)implementation for CDC based device
    By talk_to_vivekmishra in forum CDC and Personal Profile
    Replies: 3
    Last Post: 12-30-2010, 10:07 AM
  2. need advice on a web based project development
    By orhie in forum Advanced Java
    Replies: 6
    Last Post: 08-31-2010, 10:39 AM
  3. Entity - Field-Based Access Vs Property Based Access
    By CatchSandeepVaid in forum Enterprise JavaBeans (EJB)
    Replies: 3
    Last Post: 11-02-2009, 07:18 PM
  4. COM based component Project
    By jazz2k8 in forum New To Java
    Replies: 0
    Last Post: 07-17-2008, 09:03 AM
  5. Replies: 1
    Last Post: 07-23-2007, 11:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •