Question: Please code this in java using loops and arrays. And please include the five test cases and the reason why you used them? Given class:

Please code this in java using loops and arrays.

And please include the five test cases and the reason why you used them?

Please code this in java using loops and arrays. And please includethe five test cases and the reason why you used them? Givenclass: public class Book{ /** The ISBN of the book */ private

Given class:

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

import java.util.Scanner;

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

import java.util.Scanner;

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. 1. public int findUnique(Library other) Returns the number of books that occur in one library but not the other; this library and the other one (passed as a parameter). Use the fact that the libraries are sorted to do this efficiently. 2. public Library merge(Library other) Merges this library with another one, producing a new sorted library. If the same book appears in both libraries, then it appears twice in the merged library (i.e., duplicates are not removed and the order of duplicates does not matter). 3. public void addBook(Book bookin) Adds a book to this library, in the appropriate location so that the library remains sorted in ascending order by the ISBN of the books. If you add a book that is already in the course, then they will appear twice (the order of duplicates does not matter). To receive full marks vou must create an efficient solution that takes the fact that To receive full marks you must create an efficient solution that takes the fact that each list is sorted into account. Example Consider the following input of two libraries (myLibrary and yourLibrary) and an additional book at the end: 5 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 3 9780048232298, The Lord of the Rings, Tolkien, 1 9780062230621 , The Confidence Code, Kay, 0 9780385491037, The Robber Bride, Atwood, 3 9780071079170, The Skin We're In, Cole,5 After the test driver is completed and run with this input, the following should be produced: 9780006716693 9780007591855 9780048232298 9780385491037 9781400079179 The Last Battle The Silmarillion The Lord of the Rings The Robber Bride The Da Vinci Code Lewis 2 Tolkien 3 Tolkien 1 Atwood 3 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 NOTE: Include an @author tag with your name and student ID in the Javadoc comments for your completed Library class. 2. Testing Using the test driver provided, test your completed Library.java program with 5 different test cases (i.e. run the TestLibrary class 5 times, with different input each time.) Choose 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. 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. 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. 1. public int findUnique(Library other) Returns the number of books that occur in one library but not the other; this library and the other one (passed as a parameter). Use the fact that the libraries are sorted to do this efficiently. 2. public Library merge(Library other) Merges this library with another one, producing a new sorted library. If the same book appears in both libraries, then it appears twice in the merged library (i.e., duplicates are not removed and the order of duplicates does not matter). 3. public void addBook(Book bookin) Adds a book to this library, in the appropriate location so that the library remains sorted in ascending order by the ISBN of the books. If you add a book that is already in the course, then they will appear twice (the order of duplicates does not matter). To receive full marks vou must create an efficient solution that takes the fact that To receive full marks you must create an efficient solution that takes the fact that each list is sorted into account. Example Consider the following input of two libraries (myLibrary and yourLibrary) and an additional book at the end: 5 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 3 9780048232298, The Lord of the Rings, Tolkien, 1 9780062230621 , The Confidence Code, Kay, 0 9780385491037, The Robber Bride, Atwood, 3 9780071079170, The Skin We're In, Cole,5 After the test driver is completed and run with this input, the following should be produced: 9780006716693 9780007591855 9780048232298 9780385491037 9781400079179 The Last Battle The Silmarillion The Lord of the Rings The Robber Bride The Da Vinci Code Lewis 2 Tolkien 3 Tolkien 1 Atwood 3 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 NOTE: Include an @author tag with your name and student ID in the Javadoc comments for your completed Library class. 2. Testing Using the test driver provided, test your completed Library.java program with 5 different test cases (i.e. run the TestLibrary class 5 times, with different input each time.) Choose 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. 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

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 Databases Questions!