Question: Class Activity # 2 In this activity, you will practice using arrays of objects in Java. This is a crucial concept as it combines understanding
Class Activity #
In this activity, you will practice using arrays of objects in Java. This is a crucial concept as it combines understanding of both objectoriented programming and array data structures.
Background:
Imagine you are developing a software system for a library to track the books. Each book has attributes such as title, author, and year of publication.
Task:
Create a Java program that does the following:
Define a Book Class: Define a class named Book. It should have three private instance variables: title String author String and year int Include a constructor that allows you to set all three values at once. Also, include getter methods for each of these variables.
Display the Information about a book: Write a method in class Book that prints out the information of a book in the format: "Title by Author Year The method should use the defined getter methods to access the private variables.
Create an Array of Book Objects: In your Main class, create an array named library that can hold Book objects.
Populate the Array: Fill the library array with five different Book objects, representing books of your choice. Initialize each Book with appropriate values for title, author, and year.
Display the Information about all books in the library: Write a method in class Main that takes the array of Book objects as a parameter and prints out the information of each book in the format: "Title by Author Year Use the method to display all books information.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
