A print shop uses the following Java code to calculate daily paper use. Each return value is a number of sheets. The multiplication in HandoutJob.dailySheets() represents two separate, identical print batches.
class PrintJob { public int sheetsFor(int copies) { return 2 * copies + 1; } } class PosterJob extends PrintJob { public int dailySheets() { return sheetsFor(8) + sheetsFor(3); } } class HandoutJob extends PrintJob { public int dailySheets() { return 2 * sheetsFor(5); } } class LabelJob extends PrintJob { public int dailySheets() { return 2 * 6 + 1; } }
The shop changes only the body of PrintJob.sheetsFor() to:
return 3 * copies + 2;
All the code is then recompiled. Calculate the new return value of dailySheets() for one PosterJob, one HandoutJob, and one LabelJob. Also calculate the increase in their combined daily sheet count compared with the original code. Enter all four answers in sheets as exact integers.
Unlock full course notes by signing up
Checking subclass declarations
A developer has written these supporting Java declarations:
Consider each candidate below independently. Each candidate is added separately to the supporting declarations in the same source file. Enter yes if it compiles or no if it does not.
Output order in a three-level constructor chain
The three Java classes below form an inheritance chain. A program creates one object with new Thermometer(); and prints nothing else.
Arrange the four lines of output in the order the program prints them, from first to last.