Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in java book code public class Book{ /** The ISBN of the book */ private final long ISBN; /** The title of the book */

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

in java

book code

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 code

/** 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

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)); } }

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 is to implement three methods in Library.java, and test them appropriately (do not make any changes to the Book or TestLibrary classes). 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 is to implement three methods in Library.java, and test them appropriately (do not make any changes to the Book or TestLibrary classes). After the test driver is completed and run with this input, the following should be produced: 9780006716693 The Last Battle Lewis 2 9780007591855 The Silmarillion Tolkien 3 9780048232298 The Lord of the Rings Tolkien 1 9780385491037 The Robber Bride Atwood 3 9781400079179 The Da Vinci Code Brown 2 9780048232298 9780062230621 9780385491037 The Lord of the Rings The Confidence Code The Robber Bride Tolkien 1 Kay 0 Atwood 3 Number of unique books: 4 My Library after adding a book: 9780006716693 The Last Battle 9780007591855 The Silmarillion 9780048232298 The Lord of the Rings 9780071079170 The Skin We're In 9780385491037 The Robber Bride 9781400079179 The Da Vinci Code Lewis 2 Tolkien 3 Tolkien 1 Cole 5 Atwood 3 Brown 2 Merged Libraries: 9780006716693 The Last Battle 9780007591855 The Silmarillion 9780048232298 The Lord of the Rings 9780048232298 The Lord of the Rings 9780062230621 The Confidence Code 9780071079170 The Skin We're In 9780385491037 The Robber Bride 9780385491037 The Robber Bride 9781400079179 The Da Vinci Code Lewis 2 Tolkien 3 Tolkien 1 Tolkien 1 Kay 0 Cole 5 Atwood 3 Atwood 3 Brown 2 2. Testing Create 5 test case files to use with the test driver provided to test your completed Library.java program. Run the TestLibrary class 5 times, with different input each time. Create test cases that give you good coverage (i.e. test different scenarios). The example that is provided above may be used as one of the 5 test cases. Document each test case to explain what is being tested. 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

Database Systems For Advanced Applications 18th International Conference Dasfaa 2013 Wuhan China April 22 25 2013 Proceedings Part 2 Lncs 7826

Authors: Weiyi Meng ,Ling Feng ,Stephane Bressan ,Werner Winiwarter ,Wei Song

2013th Edition

3642374492, 978-3642374494

More Books

Students also viewed these Databases questions

Question

What magazine and ads did you choose to examine?

Answered: 1 week ago