Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

// Looks up author of selected books import java.util.*; class DebugNine1 { publ

ID: 3754562 • Letter: #

Question

// Looks up author of selected books
import java.util.*;
class DebugNine1
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
String[][] books = new String[6][2];
books[0][0] = "Ulysses";
books[0][1] = "James Joyce";
books[1][0] = "Lolita"
books[1][1] = "Vladimir Nabokov";
books[2][1] = "Huckleberry Finn";
books[2][1] = "Mark Twain";
books[3][0] = "Great Gatsby";
books[3][2] = "F. Scott Fitzgerald";
books[4][0] = "1984";
books[4][1] = "George Orwell";
books[5][5] = "Sound and the Fury";
books[5][1] = "William Faulkner";

String entry,
shortEntry,
message ="Enter the first three characters of a book title omitting "A" or "The" ";
int num, x;
boolean isFound = true;
while(!isFound)
{
System.out.println(message);
entry = input.next();
shortEntry = entry.substring(0,3);
for(x = 0; x < books.length; ++x)
if(books[x][0].startsWith(shortEntry))
{
isFound = true;
System.out.println(books[x][x] + " was written by " + books[x][1]);
x = books.length;
}
if(isFound)
System.out.println("Sorry - no such book in our database);
}
}
}

Debugging Exercise 9-1 Instructions DebugNine1.java+ The files provided in the code editor to the each case, determine and fix the problem, the program to ensure it works properly 1 // Looks up author of selected books 2 import java.util.*; 3 class DebugNine1 4 5 public static void main(String[] args) l right contain syntax and/or logic errors. In remove all syntax and coding errors, and run Grading Write your Java code in the area on the right. Use the Run button to compile and run the code. Clicking the Run Checks button wil run pre-configured tests against your code to calculate a grade Scanner input new Scanner(System.in); String[][] booksnew String[6] [2]; books[e]00]-"Ulysses" books[01"James Joyce"; books [1]]"Lolita" books[1]01]"Vladimir Nabokov" books [2]01]"Huckleberry Finn" books [2]01]"Mark Twain" books [3][]"Great Gatsby" books[3]12]"F. Scott Fitzgerald" books [4]]-"1984" books[4][1]"George Orwell"; books[5][5]"Sound and the Fury"; books[5]01]"William Faulkner"; 9 10 12 13 14 15 16 17 18 19 20 21 Once you are happy with your results, click the Submit button to record your score String entry, 23 24 shortEntry, message"Enter the first three characters of a book title omitting "A" or "The""; 25 26 27 28 29 int num, x; boolean isFound true; while(!isFound) System.out.println (message);

Explanation / Answer

Hey I have fixed all the syntax as well as logical errors and also commented the reasons for errors.It is compiled sucessfully.Please go through it ,if you have any queries do comment.

import java.util.*;
//public is added before class DebugNine1
public class DebugNine1
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
String[][] books = new String[6][2];
books[0][0] = "Ulysses";
books[0][1] = "James Joyce";
// ; missing after "Lolita"
books[1][0] = "Lolita";
books[1][1] = "Vladimir Nabokov";
books[2][1] = "Huckleberry Finn";
books[2][1] = "Mark Twain";
books[3][0] = "Great Gatsby";
//books[3][2] can not be used as size of array is declared as[6][2] .Change it to books[3][1]
books[3][1] = "F. Scott Fitzgerald";
books[4][0] = "1984";
books[4][1] = "George Orwell";
//books[5][5] can not be used as size of array is declared as[6][2] .Change it to books[5][1]
books[5][1] = "Sound and the Fury";
books[5][1] = "William Faulkner";

String entry,
shortEntry,
message ="Enter the first three characters of a book title omitting "A" or "The" ";
int num, x;
boolean isFound = true;
while(!isFound)
{
System.out.println(message);
entry = input.next();
shortEntry = entry.substring(0,3);
//change for loop,post increment should be done for x
for(x = 0; x < books.length; x++)
//add one more for loop because its a 2d array
for(num=0;num<2;num++)

if(books[x][num].startsWith(shortEntry))
{
isFound = true;
//use books[x][num] instead of books[x][1]
System.out.println(books[x][num] + " was written by " + books[x][num]);
//no use
//x = books.length;
}
if(isFound)
// double quotes missing
System.out.println("Sorry - no such book in our database");
}
}
}