Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Book.java codes: /** Represents a Book in a personal library @author L Bidlake */ public class Book{ /** The ISBN of the book */ private

Book.java codes:

/**

Represents a Book in a personal library

@author L Bidlake

*/

public class Book{

/**

The ISBN of the book

*/

private final long ISBN;

/**

The title of the book

*/

private final String TITLE;

/**

The author of the book

*/

private final String AUTHOR;

/**

The number of times the book has been read

*/

private int read;

/**

Constructs a book with the specifice ISBN, title and author.

@param isbn The ISBN of the book.

@param title The title of the book.

@param author The author of the book.

@param read The number of times the book has been read.

*/

public Book(long isbn, String title, String author, int read){

ISBN = isbn;

TITLE = title;

AUTHOR = author;

this.read = read;

}

/**

This method returns the ISBN of the book.

@return The ISBN of the book.

*/

public long getIsbn(){

return ISBN;

}

/**

This method returns the title of the book.

@return The title of the book.

*/

public String getTitle(){

return TITLE;

}

/**

This method returns the author of the book.

@return The author of the book.

*/

public String getAuthor(){

return AUTHOR;

}

/**

This method returns the number of times the book has been read.

@return The number of times the book has been read.

*/

public int getRead(){

return read;

}

/**

This method changes the number of times the book has been read.

@param readIn The number of times the book has been read.

*/

public void setRead(int readIn){

read = readIn;

}

}

Library.java codes:

import java.util.Scanner;

/**

Represents a personal library.

@author L Bidlake

*/

public class Library{

/**

A collection of books.

*/

private Book[] library;

/**

Constructs a library with the specified collection of books.

@param library A collection of books.

*/

public Library(Book[] library){

this.library = library;

}

/**

Constructs a library by reading in the specified input.

@param scanIn Input containing a list of books.

*/

public Library(Scanner scanIn){

library = new Book[scanIn.nextInt()];

scanIn.nextLine();

for(int i = 0; i

Scanner scan = new Scanner(scanIn.nextLine());

scan.useDelimiter(",");

long isbn = scan.nextLong();

String title = scan.next();

String author = scan.next();

int read = scan.nextInt();

library[i] = new Book(isbn, title, author, read);

}

}

/**

This method determines how many books occur in one library and

not the other

@param other Other library to compare books in this library.

@return The number of unique books.

*/

public int findUnique(Library other){

//TO DO: Complete this method

}

/**

This method merges two libraries (includes both if duplicates).

@param other Library to merge with this library.

@return The library containing all contents of both libraries.

*/

public Library merge(Library other){

//TO DO: Complete this method

}

/**

This method add a book in sorted order by ISBN to this library.

@param bookIn The book to be added to this library in sorted order.

*/

public void addBook(Book bookIn){

//TO DO: Complete this method

}

/**

Creates a formated print out of the library.

@return Formatted print out of the library.

*/

public String toString(){

String result = "";

for(int i = 0; i

result += library[i].getIsbn() + "\t" +

library[i].getTitle() + "\t" +

library[i].getAuthor() + "\t" +

library[i].getRead() + " ";

}

return result;

}

}

TestLibrary.java codes:

import java.util.Scanner;

/**

Driver to test the Library class.

@author L Bidlake

*/

public class TestLibrary{

public static void main(String[] args){

Scanner scan = new Scanner(System.in);

Library myLibrary = new Library(scan);

Library yourLibrary = new Library(scan);

Scanner sc = new Scanner(scan.nextLine());

sc.useDelimiter(",");

long isbn = sc.nextLong();

String title = sc.next();

String author = sc.next();

int read = sc.nextInt();

Book bookToAdd = new Book(isbn, title, author, read);

System.out.println(myLibrary);

System.out.println(yourLibrary);

System.out.println("Number of unique books: " +

myLibrary.findUnique(yourLibrary));

myLibrary.addBook(bookToAdd);

System.out.println("My Library after adding a book: " +

myLibrary);

System.out.println("Merged Libraries: ");

System.out.println(myLibrary.merge(yourLibrary));

}

}

image text in transcribed

image text in transcribed

image text in transcribed

1. Operations on Sorted Arrays: The purpose of this exercise is to provide more practice with working with loops and arrays. Here you will be writing three methods that operate on sorted arrays: finding the number of duplicate elements when comparing two arrays, merging two sorted arrays into one sorted array, and adding an element to an existing array such that the ordering is preserved. The arrays you will be creating and working with will be filled arrays (not partially filled arrays). You are provided with three java source files in D2L. One, Book.java, is a class that represents a book in someone's personal library and provides methods to access attributes, and change the number of times the book has been read. The ISBN, title and author of the book cannot be changed. The second, Library.java, represents a personal library of books, and provides constructors to create a library given an array of books or create one by reading input using a Scanner object. In the latter case the input format consists of a line with the number of books, followed by a line for each book containing values separated by commas (see example below). The library is sorted in ascending value of the ISBN (International Standard Book Number) of the books (these are unique for each book). Finally. TestLibrary.java is a simple test driver that will test each of the new methods. Your task to implement three method in Library ovo, and test them appropriately 1. public int indique/Library other) Returns the number of books that occur in one library but not the other the brary and the other one posedoso porometer). Use the format the brones resorted to do this efficiently 2. public Library merge library other) Marge this brory with another one, producing a new sorted forory, the some book appears in both bories, then it appears twice in the merged library file, duplicates are not removed and the order of duplicates does not matter Alter the test driver las completed and run with thout the following should be produced 9780006716699 The Last Battle 2 9780007591855 The Silmarillion Toikien 978000023229 The Lord of the Ringe Tolkies 1 9780305491037 The Robber hvide Atsed 9701400079179 The Da Vinci Code 2 97800482 32290 The Lord of the Ring Tolkies 1 9780062230621 The Confidence Code Kay 9780305491037 The Robber ride Al wood Number of unique booke: 4 My Library arter adding book The Last Battle Lewis 9780007591855 The Silaarillion Tolkien 9700046232290 The Lord of the Rings Tolkien ! 9700071079170 The skin Were In Colo 9780385491037 The Robber beide Atwood 978140007917 The Da Vinci Code Brown 2 Merged Libraries 9780006716693 The Last Battle 9780007591855 Levi 2 The Silmarillion Tolkion 3 The Lord of the Rings 9780048232290 9780046232291 Tolkien 1 The Lord of the Rings Tolkien 1 9780062230021 The Confidence Code Kay 0 9780071070170 The skin We're In Cole 9780385491031 The Mobber Bride Atwood 3 9780385491037 The Mabber Bride Atwood 3 9781400079179 The Da Vinci Code Brown 3. public void add ook Book bookin) Ach a book to the brary. In the appropriate location so that the fbrary remains sorted in ascending order by the 68 of the books you add a book that is already in the course, then they will appear twice the order of duplicate does not matter NOTE: Include on Gauthor tog with your name and student in the lavadoc comments for your completed Library con To receive fut marks you must create an officient solution that takes the fact that each otis sorted into account Example Consider the following input of two levaries (mibrary and yourlibrary and on additional book of the end 5 970000671663. The Last BattleLewis, 2 9780007591855, The Silmarillion, Tolkien, 3 9780041232290, The Lord of the Ringe, Tolkien, 1 9780305491037, The Robber Bride, Atwood. 3 9781400079179, The Da Vinci Code, Brown, 2 3 978004232290, The Lord of the Rings, Tolkien, 1 9700062230621, The Confidence Code, Kayo 9780385491037, The Robber hride, Atwood, 3 9780071079170, The Skis We're In, Cole, 5 2. Testing Using the test driver provided, test your completed Library Java program with S different test cases run the Tesllibrary class 5 times with different input each fimel Choose tout cases that give you good coverage lie tout different Iconarios). The example that is provided above may be used as one of the test cases Recall: you can use the redirection operator to send output to a text file from your running program. When you copy and paste your test input and corresponding results (output) into your report, be sure to explain why each test case that you chose to include is important

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transactions On Large Scale Data And Knowledge Centered Systems Xxviii Special Issue On Database And Expert Systems Applications Lncs 9940

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Qimin Chen

1st Edition

3662534541, 978-3662534540

More Books

Students also viewed these Databases questions