I am creating a GUI application and i am creating seperate classes outside of it. This is my code for one of these classes which is used to act as a database and print out the results;
class Database
{
public Database(){
int answer=1;
int count=0;
while (answer == JOptionPane.YES_OPTION);
{
CD[] data = new CD[12];
String a;
String c;
int n;
a = JOptionPane.showInputDialog("Please, enter artist name");
c = JOptionPane.showInputDialog("Please, enter CD name");
n = Integer.parseInt(JOptionPane.showInputDialog("Please enter total number of tracks"));
data[count] = new CD(a, c, n);
answer = JOptionPane.showConfirmDialog(null, "Enter another record?",
"???", JOptionPane.YES_NO_OPTION);
count++;
for (int i=0;i<count;i++){
System.out.println(data.printData());
}
}
}The problem i am having is that it was asking me to initialise my variable answer, which is set to an integer, so i can only initialise it with a number. 0 made my program freeze and i have tried several other numbers, to which i have it set above as 1, but what happens is that when it loops and i choose the yes option, it just jumps out of the loop. Can i initialise it another way?
Also, it only started asking me to initialise the variable answer when i had added this code
for (int i=0;i<count;i++){
System.out.println(data[i].printData());
}
Without this code, it was workin fine with no need for answer to be initialised. So i am not sure why this made a difference.
Any help would be great.
Cheers