Question

Using Java: 1. Create a Chapter class with a Chapter title and a number of pages...

Using Java:

1. Create a Chapter class with a Chapter title and a number of pages

2. Create a test chapters class that creates single chapters and arrays of chapters and prints them out

Homework Answers

Answer #1

# If you have a query/issue with respect to the answer, please drop a comment. I will surely try to address your query ASAP and resolve the issue

# # Please consider providing a thumbs up to this question if it helps you. by doing that, you will help other students who are facing a similar issue.

//-----------------------INPUT/OUTPUT-----------------------------

//-----------------------------------------------------------------------------

class TestChapter {

    public static void main(String[] args) {

        // creates a single chapter

        Chapter ch=new Chapter("If you really want to hear about it...",32);

        System.out.println(ch+"\n");

        // an array of chapter

        Chapter[] book=new Chapter[4];

        // intializing objects one by one

        book[0]=new Chapter("Meet Ackley and Stradlater",20);

        book[1]=new Chapter("Stradlater's date",10);

        book[2]=new Chapter("Allie, the glove, and the composition",30);

        book[3]=new Chapter("The fight",25);

        for (Chapter c: book){

            System.out.println(c+"\n");

        }

        

    }

}

// the required class

class Chapter{

   // the class attributes

    String title;

    int numberOfPages;

    // the constrtuctor

    Chapter(String title, int numberOfPages){

        this.title=title;

        this.numberOfPages=numberOfPages;

    }

    @Override

    public String toString() {

        return "Chapter Title: "+title+"\nNumber of pages: "+numberOfPages;

    }

}


//--------------------------------------------------------------------------------------------------------

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
JAVA Rational Numbers Create a Rational number class in the same style as the Complex number...
JAVA Rational Numbers Create a Rational number class in the same style as the Complex number class created in class. That is, implement the following methods: constructor add sub mul div toString You must also provide a Main class and main method to fully test your Rational number class.
Using Java code and ARRAYS, please write a program that takes in the names of four...
Using Java code and ARRAYS, please write a program that takes in the names of four individuals and prints out all the names. The number of names (4) is predetermined.
Java Create a new Drive class. * Create a Menu class. * The menu class will...
Java Create a new Drive class. * Create a Menu class. * The menu class will use the previous 4 classes you created in GCD, LCM, FACTORIAL, DIGITS The Menu will display a menu that give you the option of selecting: 1) Greatest Common Denominator 2) Lowest Common Multiple 3) Factorial 4) Number of Digits in an Integer Enter 1,2,3 or 4: When the User enter the choice, then the correct function/method is called for the class and asks the...
Class work # 12 / Chapter 6 –> Arrays 3 (two dimensional arrays) Part 1: Create...
Class work # 12 / Chapter 6 –> Arrays 3 (two dimensional arrays) Part 1: Create a 2-by-3 integer array and initialize it with 6 integers of your choice. Using nested for loops, display the contents of the array on the screen Part 2: (Continue on part 1) Display the sum of all the integers in the array that you created in part 1. Create a function Part 3: Create a function that will display the elements of the array...
Java For this assignment you need to create at least 5 classes. 1.Create a vehicle class...
Java For this assignment you need to create at least 5 classes. 1.Create a vehicle class ( super class) 2,3. Create two sub classes ( car, bus , truck train or any) for vehicle class 4 Create a subclass (sportscar or schoolbus or Goodstrain or any) for car or bus You need to use the following atleast for one class. Use a protected variable Add constructor for superclass and subclass Override a method which displays a description about the vehicle...
Solve the following using java Write a program that runs three threads, each thread randomizes a...
Solve the following using java Write a program that runs three threads, each thread randomizes a number between 1 and 100. The main thread waits for all the others to finish, calculates the maximum of the numbers, which were randomized, and prints it. Random number 1: 10 Random number 2: 38 Random number 3: 81 Max: 81 Note: You should create 3 threads in adition to the main thread. Also, you can use a single thread class and create 3...
How to create the multiple class in Java? Please elaborate it by using the example.
How to create the multiple class in Java? Please elaborate it by using the example.
1. Define a class named Book that contains:  An int data field named pages that...
1. Define a class named Book that contains:  An int data field named pages that stores the number of pages in the book.  A String data field named title that represents the title of the book.  A constructor with parameters for initializing pages and title.  The getter and setter methods for all data fields.  A toString method that returns book information, including the book title and pages.  The equals method that returns true if...
For Java. Let's get some practice using Java libraries! Create a class named Formatter. Formatter should...
For Java. Let's get some practice using Java libraries! Create a class named Formatter. Formatter should provide one public class method formatDate. It should accept a positive long representing milliseconds since 1970 and return a String containing the ISO-8601 representation of this time. Here is one example for a recent timestamp: given 1602106609897 your function should return 2020-10-07T21:36:49.897Z. Do not overthink this. The solution we are after is a single line of code. We suggest that you explore the various...
Java Question 1. Create a POJO Class (Employee) with these properties: i. ID ii. Age iii....
Java Question 1. Create a POJO Class (Employee) with these properties: i. ID ii. Age iii. Name 2. Write the class to read into the memory. (Reader to read into the memory). 3. Write a Junit test for the Employee class.