Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

**PLEASE GO THROUGH EACH STEP CAREFULLY AND THOROUGHLY, THANK YOU!** Instructions Start NetBeans. Create a new project called Lab5. Create a Java main class file

**PLEASE GO THROUGH EACH STEP CAREFULLY AND THOROUGHLY, THANK YOU!**

Instructions

  1. Start NetBeans.
  2. Create a new project called Lab5.
  3. Create a Java main class file using the class name YourlastnameLab5 with your actual last name.
  4. Create a Java class file for a Book class.
  5. Implement the Book class.
    1. 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.
    2. 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.
    3. Add accessor and mutator methods for each private instance variable.
    4. Add a void method called display that displays the book information in the following format:
    1. by Author (YearPublished)
    1. example, the book Parable of the Sower by Octavia Butler, which was first published in 1993 would be displayed as:
    1. of the Sower by Octavia Butler (1993)
  1. Add unit tests for the Book class to your main class.
    1. Write a static void method called testBookConstructor that takes a Book object as a parameter and calls each of the accessor methods and displays the results.
    2. Write a static void method called testBookDisplay that takes a Book object as a parameter and calls the display method on that object.
    3. In the main method add code that creates a Book object, then calls testBookConstructor and testBookDisplay with the Book object as an argument.
    4. The output of your program should look something like this:
    1. Book constructor book title: Parable of the Sower book author: Octavia Butler year published 1993 Book.display() Parable of the Sower by Octavia Butler (1993)
  1. Run the program to make sure it works.
  2. Create a Java class file for a Library class.
  3. Implement the Library class.
    1. 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.
    2. 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.
    3. Add a public accessor method for the number of books.
    4. 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.
    5. Add a stub for a private method called addBooks that has no parameters and does not return a value. For now the code can just display a message that the method was called.
  4. Add unit tests for the Library class in your main class.
    1. 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.
    2. Write a static void method called testLibraryAddBooks that takes a Library object as a parameter and calls the addBooks method on the parameter.
    3. Write a static void method called testLibraryDisplay that takes a Library object as a parameter and calls the display method on the parameter.
    4. In the main method add code that creates a Library object, then calls testLibraryGetNumBooks, testLibraryAddBooks and testLibraryDisplay with the Book object as an argument.
    5. The output should look something like this:
    1. Library.getNumBooks() Number of books: 2 Library.addBooks() Library addBooks stub Library.display() Library display stub
  1. Implement the addBooks method of the Library class to do the following:
    1. Prompt the user for the title, author, and year that book number 1 was published.
    2. Create a Book object with the input provided.
    3. Store the Book object in the array at index 0.
    4. Repeat the previous three steps using a for loop until all of the items in the array have been assigned a Book object.
    5. The prompts and user input should look something like this:
    1. 1 title: Parable of the Sower 1 author: Octavia Butler 1 year of publication: 1993

    1. 2 title: The Handmaid's Tale 2 author: Margaret Atwood 2 year of publication: 1985
  1. Run your program to see if the addBooks method works correctly.
  2. 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:
  1. of the Sower by Octavia Butler (1993) The Handmaid's Tale by Margaret Atwood (1985)
  1. Run your program to see if the display method works properly when called after addBooks has been called on the same Library object.
  2. Add an additional call to testLibraryDisplay before the call to testLibraryAddBooks to see what happens if the display method is called on a newly created Library object.
  3. Fix the Library class:
    1. Add a private instance variable of type boolean to use as a flag to determine of the library is empty.
    2. Set this flag to true in the constructor, indicating that the library is empty.
    3. Set this flag to false in the addBooks method to indicate that the library is no longer empty.
    4. 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.
  4. Run your program to see if display works correctly in both cases. The entire output of the program should look something like this:
  1. Book constructor book title: Parable of the Sower book author: Octavia Butler year published 1993

  1. Book.display() Parable of the Sower by Octavia Butler (1993) Library.getNumBooks() Number of books: 2 Library.display() The library is empty. Library.addBooks() 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 Sower by Octavia Butler (1993) The Handmaid's Tale by Margaret Atwood (1985)
  1. 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 2010 Barcelona Spain September 2010 Proceedings Part 1 Lnai 6321

Authors: Jose L. Balcazar ,Francesco Bonchi ,Aristides Gionis ,Michele Sebag

2010th Edition

364215879X, 978-3642158797

More Books

Students also viewed these Databases questions

Question

c. What were you expected to do when you grew up?

Answered: 1 week ago

Question

4. Describe how cultural values influence communication.

Answered: 1 week ago

Question

3. Identify and describe nine cultural value orientations.

Answered: 1 week ago