2. Write a program named Lab19B that creates an ArrayList of objects. The program will have...
Fantastic news! We've Found the answer you've been seeking!
Question:
![image text in transcribed](https://s3.amazonaws.com/si.experts.images/answers/2024/05/66509e6f3e17e_47166509e6f2c9fa.jpg)
![image text in transcribed](https://s3.amazonaws.com/si.experts.images/answers/2024/05/66509e6f949e4_47166509e6f72794.jpg)
Transcribed Image Text:
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. www 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). Much Ado About Nothing William Shakespeare 246 Lost Horizon James Hilton 166 Alas, Babylon Pat Frank 352 pages I, Robot Isaac Asimov 400 Hitchhiker's Guide to the Galaxy Douglas Adams 320 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. www 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). Much Ado About Nothing William Shakespeare 246 Lost Horizon James Hilton 166 Alas, Babylon Pat Frank 352 pages I, Robot Isaac Asimov 400 Hitchhiker's Guide to the Galaxy Douglas Adams 320
Expert Answer:
Posted Date:
Students also viewed these programming questions
-
Suppose that your bank imposes the following fees and/ or service charges. Explain the banks rationale and describe how you would respond as a customer. a. $ 1.50 per item for use of an ATM run by an...
-
What role can frustration, stress, and emotional disturbance play in the increase in incivility in organizations?
-
What are the contract rate and the market rate for bonds?
-
Farrar University offers an extensive continuing education program in many cities throughout the state. For the convenience of its faculty and administrative staff and to save costs, the university...
-
zara using the Ansoff Matrix, suggest a roadmap for diversification over the next three years
-
Requirement 2. Calculate the rate of return on total assets for 2019 and 2018. Begin by selecting the formula to calculate the rate of return on total assets. Rate of return on total assets Now,...
-
What is the secret sauce to Wendy's dynamite social media strategy, especially on Twitter
-
List the result of below code block; var testStrList =new string[] {"ac", "xyz", "acc", "ddd", "ece", "fff" }; testStrList.Where(p => p.Contains("c")).OrderByDescending (p => p).ThenBy (p =>...
-
MEEN 315-201: Spring 2021 Q3. (20 points) Exam 1 A piston-cylinder assembly containing 1 lbm-nitrogen gas at 50 lbf/in, 780 'R, is compressed adiabatically to 100 lbf/in. The compression process is...
-
See Figure below. Assume the capacitor is initially uncharged. At t=0, the switch is closed. R ww E R R +0 c Fe C= a) Suppose the switch is closed at t=0. Write down three simultaneous equations for...
-
Wren Co. manufactures and sells two products with selling prices and variable costs as follows: A B Selling price $18.00 $22.00 Variable costs 12.00 14.00 Wren's total annual fixed costs are $38,400....
-
A liquid that occupies a volume of 2.68 L has a mass of 2.40 kg. What is the density of the liquid in kg/L? density=[?] kg/L
-
FDI reports 2005 net income of $250,000 and pays preferred dividends of $70,000. On January I, 2005, FDI had 25,000 outstanding common shares, and it purchased 5,000 treasury shares on July I. Its...
-
What EPS figures are reported for a complex capital structure company?
-
How are organization expenses reported?
![Mobile App Logo](https://dsd5zvtm8ll6.cloudfront.net/includes/images/mobile/finalLogo.png)
Study smarter with the SolutionInn App