able[[Course Title, able[[Object-Oriented],[Programming]],Course Code,CSCI 211],[Semester,Spring 2024,Date,March 25, 2024]]
Student Name:
ID
Class Activity #2
In this activity, you will practice using arrays of objects in Java. This is a crucial concept as it combines understanding of both object-oriented 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 5 Book objects.
Populate the Array: Fill the library array with five (5) 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.
Course Title
Object-Oriented Programming
Course Code
CSCI 211
Semester
Spring 2024
Date
March 25, 2024
Student Name:
ID
Class Activity #2
In this activity, you will practice using arrays of objects in Java. This is a crucial concep
as it combines understanding of both object-oriented 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
1.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.
2. 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.
3. Create an Array of Book Objects: In your Main class, create an array named library that can hold 5 Book objects.
4.Populate the Array: Fill the library array with five (5) different Book objects representing books of your choice. Initialize each Book with appropriate values for title, author, and year.
5.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.
<Answer>
<Screenshots of Program Execution>