Loading...
Loading...
A digital library has limited storage. Every item has a title and a size in MB; a book also has an author and pages, and a video a director and minutes. An item that does not fit in the free space is refused.
Write Content (private title and size, String label()), and Book and Video that extend it; each child's label() adds its own details to super.label().
book TITLE size AUTHOR pages or video TITLE size DIRECTOR minutes (one-word values).ADDED label or NO SPACE TITLE. Then USED u OF L MB, PAGES p (total of added books) and MINUTES m (total of added videos).Example
Input
1000 3 book Gitanjali 5 Tagore 120 video Java_Intro 900 Ravi 45 video Big_Film 200 Meera 150
Output
ADDED Gitanjali [5 MB] book by Tagore, 120 pages ADDED Java_Intro [900 MB] video by Ravi, 45 min NO SPACE Big_Film USED 905 OF 1000 MB PAGES 120 MINUTES 45
After 905 MB, the 200 MB film does not fit.
Try the problem first. Open one hint at a time.
Content.label() returns title [size MB]; Book.label() appends book by AUTHOR, p pages.
Give Content a getSize() getter so main can check used + size <= L.
Keep used, the page total and the minute total in main.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor