Books N Authors
Books N Authors
Arrays;
import java.util.Scanner;
}
}
class Business{
public static Books[] getBooksBelongingToGenre(Books[] arr2, String genre2,
double discount){
Books[] refined = new Books[0];
for(int i=0; i<arr2.length; i++){
if(arr2[i].getGenre().equalsIgnoreCase(genre2)){
refined = Arrays.copyOf(refined, refined.length+1);
// refined[refined.length-1] = arr2[i];
arr2[i].applyDiscount(discount); // Apply discount method
refined[refined.length - 1] = arr2[i]; // Add to refined array
}
}
if (refined.length == 0){
return null;
}
else {
return refined;
}
}
}
class Author{
int authorId;
String authorName;
class Books{
int bookId;
String bookTitle;
String genre;
double price;
Author author;
public Books(int bookId, String bookTitle, String genre, double price, Author
author) {
this.bookId = bookId;
this.bookTitle = bookTitle;
this.genre = genre;
this.price = price;
this.author = author;
}
public int getBookId() {
return bookId;
}