Hi every one so have to write this simple CD / Video library program
I have written the program and it compiles and does the first 2 things on the menu and then will do the others but give me an error
here is the program code:
import java.io.*;
class librarymanagement
{
public static void main(String args[]) throws IOException
{
BufferedReader dataIn = new BufferedReader(new InputStreamReader(System.in));
int choice;
String strTemp;
String strComp = "text";
int posCD = 0;
int posMovie = 0;
int searchPos = (-1);
String [][] LibraryDB_CD = new String[100][2];
String [][] LibraryDB_Movie = new String[100][2];
LibraryDB_CD[posCD][0] = "coldplay a rush of blood to the head";
LibraryDB_CD[posCD][1] = "Available for renting";
posCD = posCD + 1;
LibraryDB_CD[posCD][0] = "coldplay parachutes";
LibraryDB_CD[posCD][1] = "Available for renting";
posCD = posCD + 1;
LibraryDB_CD[posCD][0] = "coldplay x&y";
LibraryDB_CD[posCD][1] = "Available for renting";
posCD = posCD + 1;
LibraryDB_CD[posCD][0] = "jonas brothers a little bit longer";
LibraryDB_CD[posCD][1] = "Available for renting";
posCD = posCD + 1;
LibraryDB_CD[posCD][0] = "jonas brothers jonas brothers";
LibraryDB_CD[posCD][1] = "Available for renting";
posCD = posCD + 1;
LibraryDB_Movie[posMovie][0] = "pride and prejudice";
LibraryDB_Movie[posMovie][1] = "Available for renting";
posMovie = posMovie + 1;
LibraryDB_Movie[posMovie][0] = "lord of the rings vol1";
LibraryDB_Movie[posMovie][1] = "Available for renting";
posMovie = posMovie + 1;
LibraryDB_Movie[posMovie][0] = "lord of the rings vol2";
LibraryDB_Movie[posMovie][1] = "Available for renting";
posMovie = posMovie + 1;
LibraryDB_Movie[posMovie][0] = "lord of the rings vol3";
LibraryDB_Movie[posMovie][1] = "Available for renting";
posMovie = posMovie + 1;
LibraryDB_Movie[posMovie][0] = "pirates of the caribbean 1";
LibraryDB_Movie[posMovie][1] = "Available for renting";
posMovie = posMovie + 1;
do{
System.out.println("\nLibrary DB Management System: \n");
System.out.println("1: Add a CD to Library DB");
System.out.println("2: Add a Movie to Library DB");
System.out.println("3: Check Status of a CD");
System.out.println("4: Check Status of Movie");
System.out.println("5: Return a CD");
System.out.println("6: Return a Movie");
System.out.println("7: Rent a CD");
System.out.println("8: Rent a Movie");
System.out.println("0: Exit\n");
System.out.print("Which option would you like to run: ");
strTemp = dataIn.readLine();
choice = Integer.parseInt(strTemp);
if(choice == 0)
{
System.out.print("\nThank you for using Library DB Management System");
}
if(choice == 1)
{
System.out.print("\nEnter the CD name: ");
LibraryDB_CD[posCD][0] = dataIn.readLine().toLowerCase();
LibraryDB_CD[posCD][1] = "Available for renting";
posCD = posCD + 1;
System.out.print("\ndone");
}
if(choice == 2)
{
System.out.print("\nEnter the Movie name: ");
LibraryDB_Movie[posMovie][0] = dataIn.readLine().toLowerCase();
LibraryDB_Movie[posMovie][1] = "Available for renting";
posMovie = posMovie + 1;
}
if(choice == 3)
{
System.out.print("\nEnter the CD name: ");
strComp = dataIn.readLine().toLowerCase();
for (int i=0; i< 100 ; i++)
{
if(LibraryDB_CD[i][0].compareTo (strComp) == 0)
{
searchPos = i;
System.out.println(LibraryDB_CD[i][0] + " " + LibraryDB_CD[i][1]);
System.out.println("\ndone");
}
}
//if (searchPos == -1)
//{
//System.out.println("\nThe CD was not found");
//}
}
if(choice == 4)
{
System.out.print("\nEnter the movie name: ");
strComp = dataIn.readLine().toLowerCase();
for (int i=0; i< 100 ; i++)
{
if (LibraryDB_Movie[i][0].compareTo (strComp) == 0)
{
searchPos = i;
System.out.println(LibraryDB_Movie[i][0] + " " + LibraryDB_Movie[i][1]);
}
}
if (searchPos == -1)
{
System.out.println("\nThe Movie was not found");
}
}
if(choice == 5)
{
System.out.print("\nEnter the name of the CD to be returned: ");
strComp = dataIn.readLine().toLowerCase();
for (int i=0; i< 100 ; i++)
{
if (LibraryDB_CD[i][0].compareTo (strComp) == 0)
{
searchPos = i;
LibraryDB_CD[i][1] = "Available for renting";
}
}
if (searchPos == -1)
{
System.out.println("\nThe CD was not found");
}
}
if(choice == 6)
{
System.out.print("\nEnter the name of the Movie to be returned: ");
strComp = dataIn.readLine().toLowerCase();
for (int i=0; i< 100 ; i++)
{
if (LibraryDB_Movie[i][0].compareTo (strComp) == 0)
{
searchPos = i;
LibraryDB_Movie[i][1] = "Available for renting";
}
}
if (searchPos == -1)
{
System.out.println("\nThe CD was not found");
}
}
if(choice == 7)
{
System.out.print("\nEnter the name of the CD to be rented: ");
strComp = dataIn.readLine().toLowerCase();
for (int i=0; i< 100 ; i++)
{
if (LibraryDB_CD[i][0].compareTo (strComp) == 0)
{
System.out.print("\nEnter the date it will be back for renting: ");
LibraryDB_CD[i][1] = dataIn.readLine();
searchPos = i;
}
}
if (searchPos == -1)
{
System.out.println("\nThe CD was not found");
}
}
if(choice == 8)
{
System.out.print("\nEnter the name of the Movie to be rented: ");
strComp = dataIn.readLine().toLowerCase();
for (int i=0; i< 100 ; i++)
{
if (LibraryDB_Movie[i][0].compareTo (strComp) == 0)
{
System.out.print("\nEnter the date it will be back for renting: ");
LibraryDB_Movie[i][1] = dataIn.readLine();
searchPos = i;
}
}
if (searchPos == -1)
{
System.out.println("\nThe movie was not found");
}
}
}while (choice != 0);
}
}
Here is the program running and the error:
Library DB Management System:
1: Add a CD to Library DB
2: Add a Movie to Library DB
3: Check Status of a CD
4: Check Status of Movie
5: Return a CD
6: Return a Movie
7: Rent a CD
8: Rent a Movie
0: Exit
Which option would you like to run: 1
Enter the CD name: too
done
Library DB Management System:
1: Add a CD to Library DB
2: Add a Movie to Library DB
3: Check Status of a CD
4: Check Status of Movie
5: Return a CD
6: Return a Movie
7: Rent a CD
8: Rent a Movie
0: Exit
Which option would you like to run: 3
Enter the CD name: too
too Available for renting
done
Exception in thread "main" java.lang.NullPointerException
at librarymanagement.main(librarymanagement3.java:188)
Any help greatly appreciated