Page 1 of 1

java package lab1.cscd210methods; import java.io.*; import java.util.*; import lab1.cscd210classes.Book; /** * The clas

Posted: Sun Jul 03, 2022 9:58 am
by answerhappygod
java
package lab1.cscd210methods;
import java.io.*;import java.util.*;import lab1.cscd210classes.Book;
/** * The class contains a set of methods required for the lab towork properly * * @NOTE All parameters passed to method must be passed asfinal. You don't need to write a default valueconstructor * since we don't have any class level variable. */public class CSCD210Lab1Methods{ /** * The fillArray method first creates an array ofbooks, and then fills each index of the book array with * a new Book object. * * @param fin Representing the Scanner object to thefile * @param total Representing the total number ofelements to be contained in the array * @return Book [] Representing array filled with Bookobjects * * @throws IllegalArgumentException if fin isnull * @throws IllegalArgumentException if total is< 1 * * @NOTE The file contents are comma separated valuesin the order title, isbn, pages, authors */ public static Book [] fillArray(final Scanner fin,final int total) { Book [] array = null; return array; }// end fillArray /** * The printBooks calls the toString method of bookand prints each book out followed by a CR * * @param array Representing the array of books * @param output Representing the PrintStream objectto the screen or the file * * @throws IllegalArgumentException if array is nullor the length is < 1 * @throws IllegalArgumentException if output streamis null */ public static void printBooks(final Book [] array,final PrintStream output) { }// end printBooks /** * The menu method offers the user a choicefrom:<br> * 1) Print the books to the screen<br> * 2) Print the books to a file<br> * 3) Sort the books based on naturalorder<br> * 4) Sort the books based on totalorder<br> * 5) Add a new book to the bookshelf<br> * 6) Search the bookshelf for a book<br> * 7) Quit<br> * * @param kb Representing the Scanner object to thekeyboard * @return int Representing the menu choice which isensured by you * to be between 1 and 7 inclusive * * @throws IllegalArgumentException if kb isnull * * @NOTE You must ensure the input buffer is empty atthe end of the method */ public static int menu(final Scanner kb) { if(kb == null) throw newIllegalArgumentException("bad scanner menu"); int choice; do { System.out.println("Please choosefrom the following"); System.out.println("1) Print thebooks to the screen"); System.out.println("2) Print thebooks to a file"); System.out.println("3) Sort thebooks based on natural order"); System.out.println("4) Sort thebooks based on total order"); System.out.println("5) Add a newbook to the bookshelf"); System.out.println("6) Search thebookshelf for a book"); System.out.println("7)Quit"); System.out.print("Choice -->"); choice =Integer.parseInt(kb.nextLine()); System.out.println(); }while(choice < 1 || choice > 7);
return choice; }// end menu /** * The addBook method makes a new array of the oldsize plus one<br> * Next it copies the books from the old array to thenew array<br> * Next it adds the new book in last index of the newarray * * @param array Representing the old array to becopied * @param aBook Representing the book to add to thearray * @return Book [] Representing the new array with theold books copied over * and the new book in the last index of the newarray. * * @throws IllegalArgumentException if array is nullor length < 1 * @throws IllegalArgumentException if aBook isnull * * @NOTE You must ensure the input buffer is empty atthe end of the method */ public static Book[] addBook(final Book [] array,final Book aBook) { Book [] temp = null; return temp; }// end addBook
/** * The createBook method prompts the user to entertitle, isbn, pages, and author. * Entering the information is done by the privatemethod readString. * The method must ensure that the pages is >0 * * @param kb Representing the Scanner object to thekeyboard * @return Book Representing a new Book object * * @throws IllegalArgumentException if kb isnull * * @NOTE You must ensure the input buffer is empty atthe end of the method */ public static Book createBook(final Scanner kb) { return null; }// end createBook /** * The readOutputFilename calls the readString to reada output filename * * @param kb Representing the Scanner object to thekeyboard * @return String Representing the outputfilename * * @throws IllegalArgumentException if kb isnull * * @NOTE You must ensure the input buffer is empty atthe end of the method */ public static String readOutputFilename(final Scannerkb) { if(kb == null) throw newIllegalArgumentException("Bad param readOutputFilename");
return readString("output filename",kb); } /** * The readString reads a string from the keyboard andensures the string is not null or empty * * @param type Representing a String for the prompt onwhat to enter * @param kb Representing the Scanner object to thekeyboard * @return String Representing the appropriateString * * @throws IllegalArgumentException if kb isnull * * @NOTE You must ensure the input buffer is empty atthe end of the method */ private static String readString(final String type,final Scanner kb) { if(type == null || type.isEmpty() || kb ==null) throw newIllegalArgumentException("Bad param readString"); String str=""; do { System.out.print("Please enterthe " + type + " "); str = kb.nextLine().trim(); }while(str == null || str.isEmpty()); return str; }// end readString
}// end class