Ok i've understood the use of arrays and most of it.... but my problem is no matter wat i do my program still only displays the last entry i make and not all.
i've tried a for loop in the print method but no luck. Neone know what im doing wrong.
below is my new modified program::
import javax.swing.*;
public class CdStorage
{
public static void main (String[] args)
{
String menu_choice;
int menu;
menu_choice =
JOptionPane.showInputDialog("Enter:\n 1: New CD entry\n 2: Print\n 3: Quit");
menu = Integer.parseInt(menu_choice);
CdRecord[] array = new CdRecord[5];
array[0] = new CdRecord();
int i = 0;
while (menu == 1 && i < 5)
{
array[i] . artist_name =
JOptionPane.showInputDialog("Enter Artist Name");
array[i] . album_name =
JOptionPane.showInputDialog("Enter Album Name");
array[i] . no_of_tracks =
Integer.parseInt(JOptionPane.showInputDialog("Enter Number Of Tracks"));
i = i++;
menu_choice =
JOptionPane.showInputDialog("Enter:\n 1: New CD entry\n 2: Print\n 3: Quit");
menu = Integer.parseInt(menu_choice);
if (menu == 2)
array[i].printCdRecord();
}
if (menu == 3)
System.out.println();
}//end while
}//end main
// end class CdStorage
class CdRecord
{
public String artist_name;
public String album_name;
public int no_of_tracks;
public CdRecord (String artist, String album, int tracks, int year)
{
artist_name = artist; //stores first argument passed into artist_name
album_name = album; //stores second argument passed into album_name
no_of_tracks = tracks; //stores third argument passed into no_of_tracks
}
public CdRecord()
{
artist_name = "A";
album_name = "B";
no_of_tracks = 0;
}
public void printCdRecord ()
{
System.out.println("Artist Name: " + artist_name + "\nAlbum Name: " +album_name+"\nNo. Of Tracks: " + no_of_tracks);
}
}//end class cdstorage
Code reformatted and tags added. -Narue
please if someone can let me know my problem id apreciate it!!!!