Results 1 to 5 of 5
  1. #1
    RadicalNH is offline Member
    Join Date
    Oct 2012
    Posts
    15
    Rep Power
    0

    Default FileScan into a linked list

    Im working on a video store inventory project for class where I need to read a database file in then be able to search it, and update it. I had the idea of using a filescan to read the text document into a singly linked list. The problem is the database file has is not completely uniform like im used to. There can be mulitple actors, titles, and will be different if the movie is checked out or not. Here is example of the DB file. First two numbers are the DB # and ID, then title, director, year, num actors, actors, whether its checkout out or not, check out ID, checkout date.

    19 9876
    The-Wizard-of-Oz Victor-Fleming 1939 1 Judy-Garland out 5432 11-19-10
    The-Wizard-of-Oz Victor-Fleming 1939 1 Judy-Garland in
    Star-Wars George-Lucas 1977 3 Harrison-Ford Mark-Hamill Carrie-Fisher in
    Star-Wars George-Lucas 1977 3 Harrison-Ford Mark-Hamill Carrie-Fisher in
    Star-Wars George-Lucas 1977 3 Harrison-Ford Mark-Hamill Carrie-Fisher in
    The-Terminator James-Cameron 1984 1 Arnold-Schwarzenegger out 1234 11-23-10
    The-Terminator James-Cameron 1984 1 Arnold-Schwarzenegger in
    Spider-Man Sam-Raimi 2002 2 Tobey-Maguire Kirsten-Dunst in
    Spider-Man Sam-Raimi 2002 2 Tobey-Maguire Kirsten-Dunst in
    Spider-Man Sam-Raimi 2002 2 Tobey-Maguire Kirsten-Dunst out 1234 11-19-10
    Spider-Man Sam-Raimi 2002 2 Tobey-Maguire Kirsten-Dunst in
    Spider-Man-2 Sam-Raimi 2004 2 Tobey-Maguire Kirsten-Dunst in
    Spider-Man-2 Sam-Raimi 2004 2 Tobey-Maguire Kirsten-Dunst in
    Spider-Man-2 Sam-Raimi 2004 2 Tobey-Maguire Kirsten-Dunst in
    Spider-Man-2 Sam-Raimi 2004 2 Tobey-Maguire Kirsten-Dunst in
    Spider-Man-3 Sam-Raimi 2007 2 Tobey-Maguire Kirsten-Dunst in
    Spider-Man-3 Sam-Raimi 2007 2 Tobey-Maguire Kirsten-Dunst out 5432 11-19-10
    Spider-Man-3 Sam-Raimi 2007 2 Tobey-Maguire Kirsten-Dunst in
    Spider-Man-3 Sam-Raimi 2007 2 Tobey-Maguire Kirsten-Dunst in

    Heres all the code I have so far.

    Class Video Libary
    Java Code:
    import java.io.*;
    import java.util.Scanner;
    
    public class VideoLibrary {
    	
    	private Node head;
    	private String fileName;
    	
    	//Constructor
    	public VideoLibrary()
    	{
    		head = null;
    	}
    	
    	//Adds data base to list 
    	public void addDB() throws IOException
    	{
    		int DBNum, DBID;
    		Scanner scan = new Scanner(System.in);
    		System.out.print("Please enter the DataBase file you wish to insert: ");
    		fileName = scan.next();
    		File book = new File(fileName);
    	    Scanner fileScan = new Scanner(book);
    	    
    	    DBNum = fileScan.nextInt();
    	    DBID = fileScan.nextInt();
    	    
    	    while (fileScan.hasNext())
            {
              
            }
    	    
    	    fileScan.close();
    	    scan.close();
    	    System.out.println("**Database successfully added**");
    	}
    	
    	//Runs program until "quit" is typed
    	public void run() throws IOException
    	{
    		String query;
    		Scanner scan = new Scanner(System.in);
    		addDB();
    		
    		System.out.println("**Please type 'quit' to exit program**");
    		System.out.println("**Please type 'update' to add new database file**");
    		
    		for (;;) 
            {
                System.out.print("Please enter title, actor, or director to search for: ");
                query = scan.next();
    
                if (query.equals("quit"))
                    break;
    
                if (query.equals("update"))
                   addDB();
                else
                   search(query.toLowerCase());
            }
    
            System.out.println("Thank you for using this program!");
    		scan.close();
    		
    	}
    	
    	
    	public void search(String query)
    	{
    		
    	}
    	
    }
    class node

    Java Code:
    import java.io.*;
    
    public class Node {
    	
    	private String title;
    	private String director;
    	private int year;
    	private int numActors;
    	private String[] actors = new String[numActors];
    	private boolean checkedOut;
    	private int checkOutID;
    	private String checkOutDate;
    	private Node next;
    	private int listSize;
    	
    	public Node(String title, String director, int year, int numActors, String actor, 
    		boolean checkedOut, int checkOutID, String checkOutDate)
    	{
    		this.numActors = 0;
    		this.title = title;
    		this.director = director;
    		this.year = 0;
    		this.actors[listSize] = actor;
    		this.checkedOut = false;
    		this.checkOutID = 0;
    		this.checkOutDate = "";
    		listSize++;
    		
    		next = null;
    		
    	}
    	
    	public void setNext(Node newNext)
    	{
    		next = newNext;
    	}
    	  
    	public Node getNext()
    	{
    		return next;
    	}
    	
    	public void setTitle(String t)
    	{
    	    title = t;
    	}
    	  
    	public String getTitle()
    	{
    		return title;
    	}
    	
    	public void setDirector(String d)
    	{
    		director = d;
    	}
    	
    	public String getDirector()
    	{
    		return director;
    	}
    	
    	public void setYear(int y)
    	{
    		year = y;
    	}
    	
    	public int getYear()
    	{
    		return year;
    	}
    	
    	public void setCheckOutDate(String d)
    	{
    		checkOutDate = d;
    	}
    	
    	public String getCheckOutDate()
    	{
    		return checkOutDate;
    	}
    	
    	public void setCheckOutID(int i)
    	{
    		checkOutID = i;
    	}
    	
    	public int getCheckOutID()
    	{
    		return checkOutID;
    	}
    	
    	public String getActors(int i)
    	{
    		return actors[i];
    	}
    	
    }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,009
    Rep Power
    20

    Default Re: FileScan into a linked list

    What problem are you having?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    RadicalNH is offline Member
    Join Date
    Oct 2012
    Posts
    15
    Rep Power
    0

    Default Re: FileScan into a linked list

    The problem Im having is that I cant figure out how to read in the file with the scanner when it comes to the variables that change. Such as actors, and checkedIn checkedID, date. I cant just new node(fileScan.Next(), filescana.Nexe(), fileScan.next()......

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,009
    Rep Power
    20

    Default Re: FileScan into a linked list

    You need to build the data first before creating the Node.
    Grab the first few fields into suitably named variables, up to and including the count of actors.
    Use that count to loop and populate an array (or List) of actor names.
    Then grab the in/out field, if 'out' then also grab the other two fields.

    Then create the Node from all that data.

    I would do all this in a separate method.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    RadicalNH is offline Member
    Join Date
    Oct 2012
    Posts
    15
    Rep Power
    0

    Default Re: FileScan into a linked list

    Thanks that helps, Ill give it a try!

Similar Threads

  1. Replies: 0
    Last Post: 09-25-2012, 04:07 AM
  2. Linked List, Array List time complexity
    By Rick99771977 in forum New To Java
    Replies: 4
    Last Post: 08-18-2011, 05:37 AM
  3. Replies: 4
    Last Post: 02-21-2011, 09:34 AM
  4. Linked list inside a linked list
    By viperlasson in forum New To Java
    Replies: 5
    Last Post: 07-26-2010, 11:15 PM
  5. Linked List integer list
    By igniteflow in forum Advanced Java
    Replies: 1
    Last Post: 12-10-2008, 08:53 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
  •