i m trying to do a music cd databse. i done most of it bt i dont kno how to do the search methord..can any 1 help
this is my program
import javax.swing.*;
import java.util.ArrayList;
import java.io.*;
import java.io.IOException;
public class Cd
{
public String ArtistName;
public String CdName;
public String Genre;
public int ReleasedDate;
public int NoOfTracks;
public Cd ()
{
ArtistName = JOptionPane.showInputDialog ("Enter The Artist's Name : ");
CdName = JOptionPane.showInputDialog("Enter The Cd Name :");
Genre = JOptionPane.showInputDialog("Enter The Music Genre :");
ReleasedDate = Integer.parseInt(JOptionPane.showInputDialog("Enter The ReleasedDate :"));
NoOfTracks = Integer.parseInt(JOptionPane.showInputDialog("Enter The Number Of Tracks :"));
}
public Cd (String a, String c, String g, int y, int n)
{
ArtistName = a;
CdName = c;
Genre = g;
ReleasedDate = y;
NoOfTracks = n;
}
public void printcd ()
{
String print = "Artist: " + ArtistName + " Cd: " + CdName + " Genre: " + Genre + " Year: " + ReleasedDate + " Tracks: " + NoOfTracks;
System.out.println(print);
}
public void printarray ()
{
String array = "Artist: " + ArtistName + " Cd: " + CdName + " Genre: " + Genre + " Year: " + ReleasedDate + " Tracks: " + NoOfTracks;
System.out.println(array);
}
}
class database
{
public static void main (String[] args)
{
int entry = 1;
Cd[] record = new Cd[entry];
final int SENTINEL = -1; // Sentinel block in a MultiShady chain.
String album;
String menu_choice;
int Menu;
int r;
int e;
int ARRAY_SIZE = 9;
Cd[] array = new Cd[ARRAY_SIZE];
{
array[0] = new Cd("Paul Weller", "White Pony", "Hard Rock", 2008, 21);
array[1] = new Cd("Bodyrox and Luciana", "What Planet You On", "Rock", 2008, 6);
array[2] = new Cd("Rem", "Accelerate", "Rock", 2008, 11);
array[3] = new Cd("Mariah Carey", "E=mc2: Digipack", "Pop", 2008, 10);
array[4] = new Cd("Leona Lewis", "Spirit", "Pop", 2008, 14);
array[5] = new Cd("Shayne Ward", "Breathless", "Pop", 2007, 13);
array[6] = new Cd("Mighty Underdogs", "Prelude: Ep", "Hip-Hop", 2007, 6);
array[7] = new Cd("Doniki", "Radikal Expressions", "Reggae", 2008, 14);
array[8] = new Cd(" Billy Fury", "The Complete Collection", "Rock & Roll", 2008, 29);
}
menu_choice = JOptionPane.showInputDialog("To enter a new entry TYPE 0,\n To print database TYPE 1,\n To Search TYPE 2,\n To Exit TYPE 3\n");
Menu = Integer.parseInt(menu_choice);
while (Menu != SENTINEL)
{
if (Menu == 0 )
{
for ( r = 0; r<entry; r++)
{
record[r] = new Cd();
}
for ( r = 0; r<entry; r++)
{
record[r].printcd();
}
menu_choice = JOptionPane.showInputDialog("To enter a new entry TYPE 0,\n To print database TYPE 1,\n To Search TYPE 2,\n To Exit TYPE 3\n");
Menu = Integer.parseInt(menu_choice);
}
else if (Menu == 1)
{
for (e = 0; e<ARRAY_SIZE; e++)
{
array[e].printarray();
}
menu_choice = JOptionPane.showInputDialog("To enter a new entry TYPE 0,\n To print database TYPE 1,\n To Search TYPE 2,\n To Exit TYPE 3\n");
Menu = Integer.parseInt(menu_choice);
}
else if (Menu == 3)
{
System.exit(0);
}
else if (Menu == 2)
{
album = JOptionPane.showInputDialog("Enter The Album To Search For :");
for ( e = 0; e<ARRAY_SIZE; e++)
{
if (array[e].CdName.equals(album))
array[e].printarray();
}
menu_choice = JOptionPane.showInputDialog("To enter a new entry TYPE 0,\n To print database TYPE 1,\n To Search TYPE 2,\n To Exit TYPE 3\n");
Menu = Integer.parseInt(menu_choice);
}
}
}
public void fileoutput (Cd[] array) throws IOException
{
final FileWriter outputFile = new FileWriter("CD_Database.txt");
final BufferedWriter OutputBuffer = new BufferedWriter(outputFile);
final PrintWriter printstream = new PrintWriter(OutputBuffer);
for(int e = 0; e < array.length; e++)
{
printstream.println(array[e]);
printstream.close();
}
final FileReader inputFile = new FileReader("CD_Database.txt");
final BufferedReader inputBuffer = new BufferedReader(inputFile);
String line = inputBuffer.readLine();
}
}