Question: Why is my code showing this on HyperGrade? What do I need to fix so it works? We have a file of books.csv that contains

Why is my code showing this on HyperGrade? What do I need to fix so it works? We have a file of books.csv that contains over 8,000 books. And I have attached two example questions. public class Book
{
String isbn;
String title;
String author;
String genre;
int year;
String[] tags;
public Book(String isbn, String title, String author, String genre, int year, String[] tags){
this.isbn = isbn;
this.title = title;
this.author = author;
this.genre = genre;
this.year = year;
this.tags = tags;
}
public String toString(){
return title +" by "+ author +"("+ year +")- Tags: "+ String.join(",", tags);
}
public boolean hasTag(String tag){
for (String t : tags){
if (t.equalsIgnoreCase(tag)){
return true;
}
}
return false;
}
}
*********************
import java.util.Scanner;
import java.util.ArrayList;
import java.io.File;
import java.util.List;
public class BookSearch {
public static void main(String[] args) throws Exception {
List books = loadBooks("books.csv");
Scanner scanner = new Scanner(System.in);
System.out.println("Enter tags (separated by commas):");
String input = scanner.nextLine();
String[] searchTags = input.split(",");
for (Book book : books){
for (String tag : searchTags){
if (book.hasTag(tag.trim())){
System.out.println(book);
break;
}
}
}
}
public static List loadBooks(String filename) throws Exception {
List books = new ArrayList>();
Scanner fileScanner = new Scanner(new File(filename));
fileScanner.nextLine();
while (fileScanner.hasNextLine()){
String line = fileScanner.nextLine();
String[] parts = line.split(",");
String isbn = parts[0];
String title = parts[1];
String author = parts[2];
String genre = parts[3];
int year = Integer.parseInt(parts[4]);
String[] tags = parts[5].split(";");
books.add(new Book(isbn, title, author, genre, year, tags));
}
fileScanner.close();
return books;
}
}
Why is my code showing this on HyperGrade? What

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!