Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

**I HAVE THE MAJORITY DONE, BUT I AM HAVING TROUBLE GETTING THE ENTIRE OUTPUT THE ASSIGNMENT ASKS ME TO HAVE. PLEASE HELP, THANKS.** -------------------------------------------------------------- Here

**I HAVE THE MAJORITY DONE, BUT I AM HAVING TROUBLE GETTING THE ENTIRE OUTPUT THE ASSIGNMENT ASKS ME TO HAVE. PLEASE HELP, THANKS.**

image text in transcribedimage text in transcribed

--------------------------------------------------------------

Here is what I have:

package csci2011.lab5;

/** * * @author */ public class LastnameLab5 { /** * @param args the command line arguments */ public static void main(String[] args) { Book test = new Book("Parable of the slower" , "Octavia Butler" , 1993); //Created a book object test. testBookConstructor(test); testBookDisplay(test); } //testBookConstructor method. public static void testBookConstructor(Book b){ //Call accessor methods to display the result. System.out.println("Book Constructor"); System.out.println("Book title: "+b.getName()); System.out.println("Book author: "+b.getAuthor()); System.out.println("year published "+b.getYear()); } //testBookDisplay method. public static void testBookDisplay(Book b){ //To test display method. System.out.println("Book.Display()"); b.Display(); }

}

--------------------------

package csci2011.lab5;

/** * * @author */ public class Book { //To store the name of the book. private String name; //To store the name of the author. private String author; //To store the year the book was published. private int year; Book(String name , String author , int year){ //Set the name of the book. this.name=name; //Set the name of the author. this.author=author; //Set the year it was published. this.year=year; } //Method to return all 3 parameters. public String getName(){ return name; } public String getAuthor(){ return author; } public int getYear(){ return year; } //Method to display. public void Display(){ System.out.println(name+" "+"by "+author+" ("+ year + ")"); }

}

--------------------------------------

package csci2011.lab5;

import java.util.Scanner;

/** * * @author */ public class Library { //To store the number of books. private int number; //Books array. private Book[] arr; //Constructor. Library(int num){ number = num; arr = new Book[num]; } //Return number of books. public int getNumberOfBook(){ return number; } //Stub for display. public void Display(){ System.out.println("Library display stub"); for(int i=0;i arr[i].Display(); } } //Stub for add books. private void addBooks(){ System.out.println("Library addBooks stub"); //To implement addBooks method. Scanner sc = new Scanner(System.in); //To get books. for( int i=0; i

}

Instructions 1. Start NetBeans 2. Create a new project called Labs. 3. Create a Java main class file using the class name YourlastnameLabs with your actual last name. 4. Create a Java class file for a Book class. 5. Implement the Book class. a. Add the following private instance variables to the Book class: A String representing the title of the book. A String representing the author of the book. An int representing the year the book was published b. Add a constructor that takes two Strings and an int and uses them to initialize the Book object. This class will not have a default constructor C. Add accessor and mutator methods for each private instance variable. d. Add a void method called display that displays the book information in the following format: 8. Create a Java class file for a Library class. 9. Implement the Library class. 2. Add the following private instance variables to the Library class: An int representing the number of books in the library. . An array of Book objects, representing the books in the library. 6. Add a constructor for the Library class that takes an int representing the number of books as a parameter and does the following: Initializes the number of books to the parameter value. Initializes the array of books to a new array of the correct size. c. Add a public accessor method for the number of books. d Add a stub for a public method called display that has no parameters and does not return a value. For now the code can just display a message that the method was called. e. Add a stub for a private method called addBooks that has no parameters and does not retum a value. For now the code can just display a message that the method was called 10. Add unit tests for the Library class in your main class. Write a static void method called testLibraryGetNumBooks that takes a Library object as a parameter, calls the accessor method for the number of books, and displays the result. a. Write a static void method called testLibratsAddBonks that takes a Library object as a parameter and calls the addBooks method on the parameter 6. Write a static void method called testLibrary Display that takes a Library object as a parameter and calls the display method on the parameter. c. In the main method add code that creates a Library object, then calls testLibraz:SetSumBooks. teati i carxAddBooks and testi icazianlax with the Book object as an argument. d. The output should look something like this: 1. li. by Author (YearPublished 1. . . . example, the book Parable of the Sower by Octavia Butler, which was first published in 1993 would be displayed as: 10. 5. p. of the Sower by Octavia Butler (1993) 6. Add unit tests for the Book class to your main class. p. Write a static void method called testBoakCoustouctor that takes a Book object as a parameter and calls each of the accessor methods and displays the results. 4. Write a static void method called testBook Display that takes a Book object as a parameter and calls the display method on that object. r. In the main method add code that creates a Book object, then calls testBookConstructor and testBook Display with the Book object as an argument. 9. The output of your program should look something like this: i. Library getNumBoakao Number of books: 2 LibrarxaddBookso Library add Books stub 6. . i. Book constructor book title: Parable of the Sower book author: Octavia Butler year published 1993 Library displexo Library display stub 11. Implement the addBooks method of the Library class to do the following: a. Prompt the user for the title, author, and year that book number 1 was published. b. Create a Book object with the input provided. c. Store the Book object in the array at index 0. d. Repeat the previous three steps using a for loop until all of the items in the array have been assigned a Book object. e. The prompts and user input should look something like this: Book display Parable of the Sower by Octavia Butler (1993) 7. Run the program to make sure it works. 1. i. Book constructor book title: Parable of the Sower book author: Octavia Butler year published 1993 1 title: Parable of the Sower 1 author. Octavia Butler 1 year of publication: 1993 i. Book.diaplas Parable of the Sower by Octavia Butler (1993) 11. Library.getNum Books Number of books: 2 Library.displaxo The library is empty 2 title: The Handmaid's Tale 2 author: Margaret Atwood 2 year of publication: 1985 12. Run your program to see if the addBooks, method works correctly. 13. Implement the display method of the Library class to display each book in the Library using a for-each loop and the display method of the Book. The output should look something like this: Library and Books) Book 1 title: Parable of the Sower Book 1 author Octavia Butler Book 1 year of publication: 1993 Book 2 title: The Handmaid's Tale Book 2 author Margaret Atwood Book 2 year of publication: 1985 Library.display Parable of the Sowerby Octavia Butler (1993) The Handmaid's Tale by Margaret Atwood (1985) p. of the Sower by Octavia Butler (1993) The Handmaid's Tale by Margaret Atwood (1985) 14. Run your program to see if the display method works properly when called after add Books has been called on the same Library object. 15. Add an additional call to testiclatarz Diaplay before the call to testLibrary AddBanks.to see what happens if the display method is called on a newly created Library object. 16. Fix the Library class: 2. Add a private instance variable of type boolean to use as a flag to determine of the library is empty b. Set this flag to true in the constructor, indicating that the library is empty. C. Set this flag to false in the addBooks method to indicate that the library is no longer empty d. Add code to the display so it does the following: . If the flag is true, display a message indicating that the library is empty. If the flag is false, display the books in the library. 17. Run your program to see if display works correctly in both cases. The entire output of the program should look something like this: 18. Hand in the source files, YourlastnameLab2.java, Book.java, and Library.java to the D2L assignment dropbox called Lab 5. The comments in each file should contain your name, CSCI 2011 Lab 5, and a description of what the class defined in the file does

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2016 Riva Del Garda Italy September 19 23 2016 Proceedings Part 1 Lnai 9851

Authors: Paolo Frasconi ,Niels Landwehr ,Giuseppe Manco ,Jilles Vreeken

1st Edition

3319461273, 978-3319461274

More Books

Students also viewed these Databases questions