Question

In: Computer Science

WRITE IN JAVA, please include comments and explain what you did A Book has such properties...

WRITE IN JAVA, please include comments and explain what you did

A Book has such properties as title, author, and numberOfPages. A Volume will have properties such as volumeName, numberOfBooks, and an array of book objects (Book [ ]). You are required to develop the Book and Volume classes, then write an application (DemoVolume) to test your classes. The directions below will give assistance.

Create a class called Book with the following properties using appropriate data types: Title, Author, numberOfPages, Create a second class called Volume with the following properties using appropriate data types: volumeName, numberOfBooks and Book [ ]. The Book [ ] contains an array of book objects.

Directions

Create a class called Book with the following properties using appropriate data types: Title, Author, numberOfPages,

The only methods necessary in the Book class, for this exercise, are the constructor and a toString().

Create a second class called Volume with the following properties using appropriate data types: volumeName, numberOfBooks and Book [ ]. Book [ ] will contain an array of book objects.

The only methods necessary in the Volume class, for this exercise, are the constructor, toString() and getBookArray(). The getBookArray returns a string of book properties for each book.

Create an application called DemoVolume.In the main method,

Create an array of book objects to be added to the volume.

Create a volume object called volume1.

Display the properties of volume1.

Grading

Task

Points

Book class properties created

2

Volume class created correctly

1

Constructors created correctly

2

"this" reference used effectively

1

Array of book objects created

2

Proper documentation / Pseudocode

1

Program works effectively

1

Total

10

Solutions

Expert Solution

OUTPUT SCREENSHOT :

===========================================================================

CODE:

Book.java:

public class Book {
    private String title;
    private String author;
    private int numberOfPages;

    //Constructor for Book Object
    public Book(String title, String author, int numberOfPages) {
        this.title = title;
        this.author = author;
        this.numberOfPages = numberOfPages;
    }

    @Override
    public String toString() {
        return  "Title = '" + title + '\'' +
                ", Author = '" + author + '\'' +
                ", Number Of Pages = " + numberOfPages ;
    }
}

==========================================================================

Volume.java:

public class Volume {
    private String volumeName;
    private int numberOfBooks;
    private Book[] books;

    //Constructor for Volume Object
    public Volume(String volumeName, Book[] books) {
        this.volumeName = volumeName;
        this.numberOfBooks = books.length ;
        this.books = books;
    }

    //Prints the books stored
    public void getBookArray(){
        for (Book b: this.books) {
            System.out.println(b);
        }
    }

    @Override
    public String toString(){
        return "Name of Volume: " + this.volumeName  +"\nNumber of Books: " + this.numberOfBooks + "\n";
    }
}

============================================================================

DemoVolume.java:

public class DemoVolume {
    public static void main(String[] args) {

        //Making books array
        Book[] books = { new Book("Game of Thrones","George Martin", 1200),
                         new Book("Harry Potter","JK Rowling",1500),
                         new Book("The Alchemist","Paulo Coelho", 350),
                         new Book("50 Shades of Grey","EL James",1400) };


        //Making a volume Object and adding books array to it.
        Volume voulme1 = new Volume("Volume 1", books);

        //Displaying the property of Books in Volume 1.
        System.out.println(voulme1);
        voulme1.getBookArray();
    }
}

===========================================================================


Related Solutions

Hello, Please write this program in java and include a lot of comments and please try...
Hello, Please write this program in java and include a lot of comments and please try to make it as simple/descriptive as possible since I am also learning how to code. The instructions the professor gave was: Create your own class Your own class can be anything you want Must have 3 instance variables 1 constructor variable → set the instance variables 1 method that does something useful in relation to the class Create a driver class that creates an...
Please include comments on what you are doing.   Using linked lists, write a Python program that...
Please include comments on what you are doing.   Using linked lists, write a Python program that performs the following tasks: store the records for each college found in the input file - colleges.csv - into a linked list. (File includes name and state data fields) allow the user to search the linked list for a college’s name; display a message indicating whether or not the college’s name was in the database allow the user to enter a state's name and...
JAVA CODE, USE COMMENTS TO EXPLAIN PLEASE Write a Bottle class. The Bottle will have one...
JAVA CODE, USE COMMENTS TO EXPLAIN PLEASE Write a Bottle class. The Bottle will have one private int that represents the countable value in the Bottle. Please use one of these names: cookies, marbles, M&Ms, pennies, nickels, dimes or pebbles. The class has these 14 methods: read()(please use a while loop to prompt for an acceptable value), set(int), set(Bottle), get(), (returns the value stored in Bottle), add(Bottle), subtract(Bottle), multiply(Bottle), divide(Bottle), add(int), subtract(int), multiply(int), divide(int), equals(Bottle), and toString()(toString() method will be...
JAVA CODE, BEGINERS; Please use comments to explain For all of the following words, if you...
JAVA CODE, BEGINERS; Please use comments to explain For all of the following words, if you move the first letter to the end of the word, and then spell the result backwards, you will get the original word: banana dresser grammar potato revive uneven assess Write a program that reads a word and determines whether it has this property. Continue reading and testing words until you encounter the word quit. Treat uppercase letters as lowercase letters.
Write the following program in java please. a. Include a good comment when you write the...
Write the following program in java please. a. Include a good comment when you write the method described below: Method method1 receives an integer, n, and a real number, d, and returns a real number. If the integer is positive it returns the square root of the real number added to the integer. If the integer is negative or zero it returns the absolute value of the integer multiplied by the real number. b. Write the statements from the main...
Write a complete JAVA program, including comments (worth 2 pts -- include a good comment at...
Write a complete JAVA program, including comments (worth 2 pts -- include a good comment at the top and at least one more good comment later in the program), to process data for the registrar as follows: NOTE: Include prompts. Send all output to the screen. 1. Read in the id number of a student, the number of credits the student has, and the student’s grade point average (this is a number like 3.25). Print the original data right after...
Write a Java application "WellFormedExpression.java". Start with the file attached here. Please read the comments and...
Write a Java application "WellFormedExpression.java". Start with the file attached here. Please read the comments and complete the function 'isWellFormed()'. It also has the main() to test the function with several input strings. Feel free to change and add more tests with different kinds of input data for correct implementation. Note that you need MyStack.java and Stackinterface.java in the same package. WellFormedExpression.java package apps; public class WellFormedExpression {    static boolean isWellFormed(String s) {        /**** Create a stack...
In java, (include javadoc comments for each method) design a class named Contacts that has fields...
In java, (include javadoc comments for each method) design a class named Contacts that has fields for a person’s name, phone number and email address. The class should have a no-arg constructor and a constructor that takes in all fields, appropriate setter and getter methods. Then write a program that creates at least five Contacts objects and stores them in an ArrayList. In the program create a method, that will display each object in the ArrayList. Call the method to...
write this program in java... don't forget to put comments. You are writing code for a...
write this program in java... don't forget to put comments. You are writing code for a calendar app, and need to determine the end time of a meeting. Write a method that takes a String for a time in H:MM or HH:MM format (the program must accept times that look like 9:21, 10:52, and 09:35) and prints the time 25 minutes later. For example, if the user enters 9:21 the method should output 9:46 and if the user enters 10:52...
Please use Java language with comments! Thanks! Write a program that will display multiple dots move...
Please use Java language with comments! Thanks! Write a program that will display multiple dots move across the Frame and randomly change direction when they hit the edge of the screen. Do this by creating a Dot class and making each dot an object of that class. You may reuse code written in class for this part of the assignment. Create a subclass of the Dot class called PlayerDot that is controlled by the player through keyboard input (arrow keys)...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT