Hi, I am currently working on a linked list database program which keeps track of which movies are entered into the database, along with the removal of videos and displaying how many copies of that video are available(if in the database) when searched. So far I can add and delete but I want to only increase the count number if I add a video which is already in the database and I'm not quite sure how to accomplish this. In addition I am almost positive that the search method is garbage :confused:. I am trying to use a linked list to accomplish this, here is my code so far.... any and all help would be appreciated.



import java.util.*;

public class DB
{
private static DBnode head=null; //null means "it points nowhere."
private static Scanner Scan = new Scanner(System.in);


public static void main (String[] args)
{

//loop which does the checking for the entered commands
int i = 0;
while (i <= 1)
{

//asks the user to enter the proper command
System.out.print("Please, enter a command: ");
String command = Scan.nextLine();
System.out.println("" + command);

//the following is all command string comparisons
if (command.compareTo("add") == 0)
{
System.out.print("Enter the movie title to add: ");
String video = Scan.nextLine();
int count = 0;
addb(video);
}
else if (command.compareTo("ADD") == 0)
{
System.out.print("Enter the movie title to add: ");
String video = Scan.nextLine();
int count=0;
addb(video);
}
else if (command.compareTo("SEARCH") == 0)
{
System.out.print("Enter the movie title you would like to search: ");
String video = Scan.nextLine();
search(video);
}
else if (command.compareTo("search") == 0)
{
System.out.print("Enter the movie title you would like to search: ");
String video = Scan.nextLine();
search(video);
}
else if (command.compareTo("delete") == 0)
{
System.out.print("Enter the movie title you would like to delete: ");
String video = Scan.nextLine();
remove(video);
}
else if (command.compareTo("DELETE") == 0)
{
System.out.print("Enter the movie title you would like to delete: ");
String video = Scan.nextLine();
remove(video);
}
else if ( command.compareTo("QUIT") == 0)
{
printb();
System.exit(0);
}
else if (command.compareTo("quit") == 0)
{
printb();
System.exit(0);
}
else
{
System.out.println("Error, not a correct command. Use add, search, or delete.");
}

}

}

public static void add (String videoName)
{
DBnode n = new DBnode(videoName,head);
head = n;
}
public static void addb (String videoName)
{
if
(head==null) add (videoName);
else
head.addb (videoName);
}


public static void search (String videoName)
{
if (head != null)
head = head.search (videoName);
}

public static void remove (String videoName) {

if (head != null)
head = head.remove (videoName);
}

public static int count () {

if (head==null) return 0;
return head.count();
}

public static int countv (String v) {

if (head==null) return 0;
return head.countv (v);
}

public static void print () {

if (head==null) ;
else head.print ();
System.out.println ();
}

public static void printb () {


if (head==null) ;
else head.printb ();
System.out.println ();
}
}


public class DBnode
{

private String video = "";
private int count = 0;
private DBnode next=null;

public DBnode (String v, DBnode n)
{
video = v;
next = n;
count = count + 1;
System.out.println (v+" has been added to the database with "+count+" in stock.");
}

public void setVideo (String v)
{
video = v;
}

public String getVideo ()
{
return video;
}

public void setnext (DBnode n)
{
next = n;
}

public DBnode getnext ()
{
return next;
}

public void print ()
{
System.out.println (video);
if (next==null) ;
else next.print();
}

public void printb ()
{
if (next==null) ;
else next.printb();
System.out.println (video);
}

public void addb (String videoName)
{
if (next==null)
next = new DBnode(videoName,null);
else
next.addb(videoName);
}

public DBnode search (String videoName)
{
if (video.compareTo(videoName)==0)
return next;
if (next==null)
return this;

return this;
}

public DBnode remove (String videoName)
{
if (video.compareTo(videoName)==0) return next;
if (next==null)
return this;

next = next.remove (videoName);
return this;
}

public int count ()
{
if (next==null)
return 1;
return next.count() + 1;
}

public int countv (String v)
{
int ct = 0;
if (next != null)
ct += next.count();
if (video.compareTo(v)==0)
ct++;
return ct;
}
}