I have to search a Cadillac object array to bring up results of a certain model, let's say "Escalade", and I am having trouble figuring out where my code specifically needs to be placed in order to have the results print on the console screen. I keep getting stuck in a loop when I try printing what I've got now. Everything else about my program is working, I just need to be able to display multiple results on the console screen.
Here is the code I have:
while( response != null )
{
if( response.length() > 0 )
{
count = 0;
found = false;
while( count < data.length && data[count] != null && !found )
{
item = data[count].getModel();
if( item.equalsIgnoreCase( response ) )
{
found = true;
}
else{
count++;
}
message = "Model: " + data[count].getModel() + "\n" +
"Stock Number: " + data[count].getStockNum() + "\n" +
"Color : " + data[count].getColor() + "\n" +
"Price : " + data[count].getPrice();
System.out.print( message );
}
if( !found )
message = "Model not found in array.";
}
}
response = JOptionPane.showInputDialog( prompt );
}
Also, the second part of the searching is to display search results for cars that are within $3000 of the user's input, and would definitely appreciate some guidance on that as well, since these two types of searches are relatively similar.