// Name : Matthew Reeves // This is a program to create an inventory for books import java.util.Scanner; //creates BookInvTest class public class BookInvTest { //main method which collects all information from user public static void main( String args[] ) { //initializes local variables for method String titl; String auth; String publ; int pyear; String isbn; //creates scanner object Scanner input= new Scanner(System.in); //prompts for and stores attribute info from user System.out.print("\nEnter the book's title: "); titl=input.nextLine(); System.out.println(); System.out.print("Enter the book's author: "); auth=input.nextLine(); System.out.println(); System.out.print("Enter the book's publisher: "); publ=input.nextLine(); System.out.println(); System.out.print("Enter the book's publication year: "); pyear=input.nextInt(); input.nextLine(); System.out.println(); System.out.print("Enter the book's ISBN number: "); isbn=input.nextLine(); System.out.println(); //creates Book object using user input Book bookEntry=new Book(titl,auth,publ,pyear,isbn); //print to screen all info entered by user with appropriate labels System.out.printf("%s\n",bookEntry.toString()); //creates Inventory object, and passes book info to Inventory method BookInventory bookInv=new BookInventory(bookEntry); //prints to screen initial inventory System.out.printf("Initial Book Inventory:\n%s\n",bookInv.toString()); //prompts for and stores number of books to add to inventory System.out.print("\nEnter the number of books to add to inventory: "); int numadd=input.nextInt(); //validates user entered value for books to add if (bookInv.addBook(numadd)==false) { System.out.println("Inventory not updated - invalid number of books entered"); } else { System.out.printf("Initial Book Inventory:\n%s\n",bookInv.toString()); } //prompts for and stores number of books to remove from inventory System.out.print("\nEnter the number of books to remove from inventory: "); int numrmv=input.nextInt(); //validates user entered value for books to remove if (bookInv.removeBook(numrmv)==false) { System.out.println("Inventory not updated - invalid number of books entered"); } else { System.out.printf("Initial Book Inventory:\n%s\n",bookInv.toString()); } //creates a new Book object, identical to but separate from the original Book newBook=new Book(bookEntry); //prints attributes for copied book with appropriate labels System.out.printf("\nThe copied book =\n%s\n",newBook.toString()); } }