can anyone help me look over my code?

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.

package courses;

import java.util.LinkedList;

public class Course {
	private String department;
	private int coursenumber;
	private String coursetitle;
	private LinkedList<Course> prerequisites;
	private LinkedList<Course> subsequents;
	private LinkedList<Course> first;

	public Course() {
		department = null;
		coursenumber = 0;
		coursetitle = null;

	}

	public Course(String dep, int cNumber, String cTitle) {
		department = dep;
		coursenumber = cNumber;
		coursetitle = cTitle;

	}

	public String getDepartment() {
		return department;
	}

	public int getCoursenumber() {
		return coursenumber;
	}

	public String getCoursetitle() {
		return coursetitle;
	}

	public LinkedList<Course> getPrerequisites() {
		return prerequisites;
	}

	public LinkedList<Course> getSubsequents() {
		return subsequents;
	}

	public void setNext(LinkedList<Course> dnode) {
		subsequents = dnode;
	}

	public void setPrevious(LinkedList<Course> dnode) {
		prerequisites = dnode;
	}

	public void addP() {
		LinkedList<Course> node = new LinkedList<Course>();
		node.addAll(prerequisites);
		first = node;

	}

	public void addS() {
		LinkedList<Course> node = new LinkedList<Course>();
		node.addAll(subsequents);
		first = node;

	}

	public String toString() {
		return "The departemnt is: " + department + "\n"
				+ "The course is called: " + coursetitle + "\n"
				+ "The course number is: " + coursenumber + "\n";

	}

}

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.

package courses;

import java.util.Collection;
import java.util.LinkedList;






public class CourseCatalog{
	 private String name;
	 private Course count; 
	 private int count2;
	 private Course contents; 

	
	public CourseCatalog(String filename) {
		name = filename;
	}

	
	public Course  get(){
		return contents;
		
	}
	public Course  set(){
		return contents=count;
		
	}
	   public Course  add (LinkedList<Course>  element){
		   Course node = new Course ();
	         node.setNext(element);
	         contents = node;
	         count2++;
			return node;
	   }
	   
	
	   public Course size()
	   {
	      return count;
	   }
	public String toString() {
		return toString();
	}
}

The CourseManager class

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;
		
	}


}

The CourseTester class
Besides constructing and printing CourseCatalog objects, no other method of CourseCatalog or Course should be called. To add/remove courses, create a String array and loop thru it. An example plan you might follow is:

Construct "small" catalog.
Print catalog.
Construct manager.
Test all required methods of CourseManager. You should ensure that you can or cannot add CS 3343 as appropriate. You should ensure that you can or cannot remove CS 1713 as appropriate.
Construct "big" catalog.
and so on

package courses;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;




public class CourseTester {

	/**
	 * @param args
	 * @throws FileNotFoundException 
	 */
	public static void main(String[] args) throws FileNotFoundException {
	System.out.println("project 2 written by matthew gamble");

	Scanner in = new Scanner(new File("smallcatalog.txt"));
	while (in.hasNext()) {
	    String token = in.next();
	   token.length();
	  
	    
	    
	    
	}
System.out.println(in);


	}}

Recommended Answers

All 2 Replies

Could you be more specific about what you need help with? What isn't working, and so on.

my tester isnt working pretty much and also i just want to see if im foloowing the instructions in with my code

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.