Answered step by step
Verified Expert Solution
Question
1 Approved Answer
2. Write a program named Lab19B that creates an ArrayList of objects. The program will have 2 classes, the main class and a second
2. Write a program named Lab19B that creates an ArrayList of objects. The program will have 2 classes, the main class and a second class named Book. The Book class should have the following: Instance variables: A String variable to hold the book title A String variable to hold the book's author An int variable to hold the number of pages in the book A constructor that accepts a title, author and number of pages and fills in the instance variables. An int method that returns the number of pages (no parameters) A String method that returns the title (no parameters) A String method named toString that returns a string with each instance variable value and a label in front of each. (If you don't remember the basics of the toString method, look it up in the Chapter 3 PowerPoint in the Java Review Materials) Back in the main class, do the following: Create an ArrayList of Book objects. Read each book's title, author & number of pages from the text file (Lab19B.txt) Note - the title, author & nbr of pages will each be on their own line. Create a Book object with those values for each book and add it to the ArrayList After the ArrayList is created, loop through it and calculate the average number of pages in the books. Print that average with a label. Loop through the ArrayList and print the information for each book (using the toString method shortcut).
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started