Question
//error! need to be fixed; //Chapter 9, Debugging Exercises;Java programming;Joyce Farrell, 8th ed. //output 1 // Looks up author of selected books 2 import javax.swing.*;
//error! need to be fixed;
//Chapter 9, Debugging Exercises;Java programming;Joyce Farrell, 8th ed.
//output
1 // Looks up author of selected books 2 import javax.swing.*; 3 class FixDebugNine1 4 { 5 public static void main(String[] args) 6 { 7 String[][] books = new String[6][2]; 8 books[0][0] = "Ulysses"; 9 books[0][1] = "James Joyce"; 10 books[1][0] = "Lolita"; 11 books[1][1] = "Vladimir Nabokov"; 12 books[2][0] = "Huckleberry Finn"; 13 books[0][1] = "Mark Twain"; 14 books[3][0] = "Great Gatsby"; 15 books[3][2] = "F. Scott Fitzgerald"; 16 books[4][0] = "1984"; 17 books[3][1] = "George Orwell"; 18 books[5][0] = "Sound and the Fury"; 19 books[5][1] = "William Faulkner"; 20 21 String entry, 22 shortEntry, 23 message ="Enter the first three characters of a book title omitting \"A\" or \"The\" "; 24 int num, x; 25 boolean isFound = true; 26 while(!isFound) 27 { 28 entry = JOptionPane.showInputDialog(null, message); 29 shortEntry = entry.substring(3); 30 for(x = 0; x < books.length; ++x) 31 if(books[x][0].startsWith(entry)) 32 { 33 isFound = true; 34 JOptionPane.showMessageDialog(null, 35 books[x][0] + " was written by " + books[x][2]); 36 x = books.length; 37 } 38 if(isFound) 39 JOptionPane.showMessageDialog(null, "Sorry - no such book in our database"); 40 } 41 } 42 }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started