QuestionQuestion

Transcribed TextTranscribed Text

The Assignment Using inheritance, make a basic library that can hold four kinds of materials. Resource Resource.java should be an abstract class and a parent class for the other four kinds of materials. It should have instance variables for: ● Title ● Publisher ● Type (what kind of resource it is) ● Is it electronic or not ● Is it checked-out or not ● Who it is checked-out by Use your judgement about what type each field should be. int and boolean are faster to use and search than String, and take up less space; use simpler types when you can. Resource should also have the following methods: ● a constructor that requires the following information be passed in when a new Resource is created: title, publisher, type, if it’s electronic or not. All Resources start as not checked out. ● getters for Title, Type, Is it checked-out or not, Is electronic, and Who it is checked-out to ● a toString method that returns a string containing the variable information in an easy-toread way. ● a method to check out a resource. Checking out a resource should require a string of who it’s going to, set the is-checked-out variable to true, and set who it’s checked out to to the appropriate name. ● a method to check in a resource. Checking in a resource should set the is-checked-out variable to false, and who it’s checked out by to null; it doesn’t need any parameters. Use your judgement about parameters, return values, and similar. Book, Journal, CD, DVD Each of these classes should inherit from Resource. Their constructors should call their parent constructor, and set their respective Types correctly: Book.java’s Type should be “Book”, Journal.java’s Type should be “Journal”, etc. Each class should overwrite the toString method, printing out all relevant variables in an easy-to-read way. An example is below: Each class has different required variables. Be sure to write getters and setters for each! The Book.java specific fields are: ● Author ● Number of pages ● Publication year ● Genre The Journal.java specific fields are: ● Range of years published ● How often they are published (publishing frequency -- could be monthly, quarterly, etc.) ● Is it electronic or not: This is not a new field, but all Journals are assumed to be electronic The CD.java specific fields are: ● Artist ● Recording company (use Publisher field) ● Year ● Length ● Is it electronic or not: This is not a new field, but all CDs are assumed to be NOT electronic The DVD.java specific fields are: ● Year ● Length ● Performers ● Genre ● Is it electronic or not: This is not a new field, but all DVDs are assumed to be NOT electronic Library This class should be able to perform different tasks on an array of Resources. Write the following methods: ● getAllCheckedOut, which takes an array of Resource objects, and returns a smaller array of Resource objects. Because you’re using arrays, you’ll need to first count how many items are checked out, then create an array of that size, then copy all checked-out items into the new array. ● getAllUserHasCheckedOut, which takes an array of Resource objects and a String, and returns a smaller array of Resource objects. Similarly to above, you need to count how many items someone has checked out before creating the array and copying the Resource objects into it. Additionally, you need to figure out what to do if that particular person has nothing checked out. ● getAllOfType, which takes an array of Resource objects and a String, and returns a smaller array of Resource objects. You can check what type an object is either by using the getType method you wrote A main method is not required for submission; however, it is recommended so you can test your code. Hints and Advice It’s a bad idea to try writing every class at once, and only then compiling. A suggested order of operations: 1. Write Resource.java. Start with the variables, the constructor, and toString. 2. Create Library, but only write the main method. Create an array of four or so Resources. Set them, and make sure all the methods in Resource work as expected. 3. Keep adding and testing methods in Resource until you have them all. 4. Write one of the child class, such as Book.java. Start with the variables, the constructor, and toString. 5. In the main method of Library, replace the Resources with Books. Make sure everything still works as expected. a. The array can still be of type Resource, since all Books are Resources 6. Write another child class, such as DVD. 7. In the main method of Library, add some DVDs to the array. Again, make sure things still work. a. Your array should be of Resources, since both DVDs and Books are Resources, so both can be added to arrays. 8. Repeat the above two steps until all child classes are complete. 9. Write one method at a time in Library, testing each after you write it. 10. Compile your code with the test file above. Make any adjustments so they run well together. Null Pointer Exceptions You can’t call a method on an object that’s null, or you’ll get a NullPointerException. A good check to include in all Library methods is testing if a variable is null before calling methods on it. The check can be written like so:

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

*
*
*
* Description: This is the Book Class. The class constructors, methods, and
* setting values for the book class. This class is a child to the Resource
* Class. The toString method to assist in outputting.
*/
package library;

// Beginning of Book Class
public class Book extends Resource
{
    // Declare class variables
    private String author;
    private int noOfPages;
    private int publishYear;
    private String genres;
   
    // Beginning of Book Default Constructor
    public Book()
    {
       // Setting variables for the constructor
       author="";
       noOfPages=0;
       publishYear=0;
       genres="";
    }
    // Ending of Book Default Constructor
   
    // Beginning of Book Constrctor with parameters
    public Book(String title,String author, String publisher,int noOfPages,
            int publishYear, String genres,boolean isCheckedOut)
    {
       // Setting values for constructor
       this.title=title;
       this.author=author;
       this.publisher=publisher;
       this.noOfPages=noOfPages;
       this.publishYear=publishYear;
       this.genres=genres;
       this.type="Book";
       this.isElectronic=false;
    }
    // Ending of Book Constrctor with parameters

    // Beginning of getAuthor method
    public String getAuthor()
    {
       // Returns author variable
       return author;
    }
    // Ending of getAuthor method
   
    // Beginning of getNoOfPages method
    public int getNoOfPages...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

$10.00
for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Computer Science - Other Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats