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
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 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.
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...
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...
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...
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.
Problem Statement: Write a Java program “HW6_lastname.java” that prints a program title and a menu with...
Problem Statement: Write a Java program “HW6_lastname.java” that prints a program title and a menu with four items. The user should then be prompted to make a selection from the menu and based on their selection the program will perform the selected procedure. The title and menu should be as the following: Student name: <your name should be printed> CIS 232 Introduction to Programming Programming Project 6 Due Date: October 23, 2020 Instructor: Dr. Lomako ******************************** 1.     Compute Angles                               *...
Using C++, Python, or Java, write a program that: In this programming exercise you will perform...
Using C++, Python, or Java, write a program that: In this programming exercise you will perform an empirical analysis of the QuickSort algorithm to study the actual average case behavior and compare it to the mathematically predicted behavior. That is, you will write a program that counts the number of comparisons performed by QuickSort on an array of a given size. You will run the program on a large number of arrays of a certain size and determine the average...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT