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
# 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;
}
}
//--------------------------------------------------------------------------------------------------------
Get Answers For Free
Most questions answered within 1 hours.