Loading...
Loading...
A college library gives every new member a card number like LIB-0042. Numbers continue from last year, so the first card this year comes right after the last one already issued.
Write a class LibraryCard with a static final String PREFIX = "LIB-", a static int issued shared by all cards, and final fields number and holder set in the constructor, which takes the next number. In main, set LibraryCard.issued from the input before creating any card.
number holder, with the number padded to 4 digits, then CARDS ISSUED total.Example
Input
41 3 Asha Ravi Meena
Output
LIB-0042 Asha LIB-0043 Ravi LIB-0044 Meena CARDS ISSUED 44
Last year ended at card 41, so this year starts at 42.
Try the problem first. Open one hint at a time.
A static field has one copy for the whole class, so every constructor call sees the number the previous card left behind.
In the constructor, add 1 to issued first and then build the number from it.
String.format("%04d", x) pads x with zeros to 4 digits.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor