Ok so Im trying to create a constructor that reads input from a text file. Which I got it to do. Then adds the information to a LinkedList.

public class CourseCatalog<T> {
	private BufferedReader read;
	private LinkedList<Course> catalog;
public CourseCatalog(String filename) throws FileNotFoundException {
		catalog = new LinkedList<Course>();
        try {
            //Construct the BufferedReader object
            this.read = new BufferedReader(new FileReader(filename));
            String line = null;
            while ((line = read.readLine()) != null) {
        	  //Process the data

        } catch (FileNotFoundException ex) {
        } catch (IOException ex) {
        } finally {
            //Close the BufferedReader
            try {
                if (read != null)
            } catch (IOException ex) {

The text file contains a bunch of differnt courses like this.
Course: MAT 1214
Title: Calculus I
Prerequisite: none

Course: MAT 1224
Title: Calculus II
Prerequisite: MAT 1214

So my code right now just reads the .txt file and outputs whats in it. Anybody have any suggestions or could point me in the right direction of how I would go about adding that information to a LinkedList<Course>. The constructor of my Course class looks like this.

public Course(String dep, int num, String title) {
		department = dep;
		coursenumber = num;
		coursetitle = title;
		prerequisites = new LinkedList<String>();
		subsequents = new LinkedList<String>();

Take the input from the file and use it to create a Course object. There's some parsing involved there, but you should be able to do that, it's just looking at Strings as they come in and making decisions.

When you finish making a Course, add it to the list using the methods found here.

This article has been dead for over six months. Start a new discussion instead.