import javax.swing.JOptionPane; import java.io.*; public class Find1 { public static void main (String[] args) throws IOException { String file = "output.dat"; BufferedReader inFile = new BufferedReader (new FileReader(file)); String message, itemToFind; String item, price; boolean found = false; // display input dialog to user message = "This program asks the user to enter the name of "; message += "an item\nthen there is a search of a data file " ; message += "for the item.\nEither the price of the item or a "; message += "message stating\nthat the item was not found is "; message += "displayed."; itemToFind = JOptionPane.showInputDialog (message); // read first item from the file item = inFile.readLine(); while (!found && item != null) { // read the price price = inFile.readLine(); // is this the item we're looking for? if (item.equals(itemToFind)) { found = true; message = "The " + item + " is available for $" + price; JOptionPane.showMessageDialog (null, message, "Item Price", JOptionPane.INFORMATION_MESSAGE); } // read next item item = inFile.readLine(); } if (!found) { JOptionPane.showMessageDialog (null, itemToFind + " not found", "Sorry", JOptionPane.INFORMATION_MESSAGE); } // close the input file and exit inFile.close(); System.exit(0); } }