Loading...
Loading...
A school library prints a card for every book and names the oldest one.
Write a class Book with fields title, author and year and methods String label() and int age(int currentYear). Store the books in a Book[] array, print each card, and then print the title of the oldest book (the first one if two are equally old).
title by author (year), age years old, then one line Oldest: title.Example
Input
2 2025 Wings of Fire A. P. J. Abdul Kalam 1999 Gitanjali Rabindranath Tagore 1910
Output
Wings of Fire by A. P. J. Abdul Kalam (1999), 26 years old Gitanjali by Rabindranath Tagore (1910), 115 years old Oldest: Gitanjali
Gitanjali is 115 years old, so it is the oldest.
Try the problem first. Open one hint at a time.
Titles have spaces, so read every line with nextLine() and turn the year into a number with Integer.parseInt.
Keep a Book oldest variable that starts at books[0] and change it only when a strictly older book appears.
label() joins the fields into one String.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor