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) {
          if(line.contains("Course")){ 
        	
        	  //Process the data
                 
            	
        		System.out.println(line);
          }

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

The text file contains a bunch of differnt courses like this.
Ex:
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.

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.