1. Suppose you are writing a driver class called PadDriver, whichwill make use o
ID: 3612780 • Letter: 1
Question
1. Suppose you are writing a driver class called PadDriver, whichwill make use of the PaperPad class (see other side.)a) In this driver class create a PaperPad object with owner Jilland with 100 sheets of paper. Call this object myPad.
PaperPad myPad = new PaperPad("Jill", 100);
b) Create another Paperpad object called somePad. This pad objectshould be associated with owner Jack, and should have a randomnumber of sheets between 0 and 199 (inclusive: both 0 and 199 arepossible). (Hint: use the random method from the Math class).
PaperPad somePad = new PaperPad("Jack",(int)(Math.random()*200));
c) Add a statement to the driver class that prints to the consolethe total number of sheets in myPad and somePad combined.
System.out.println(myPad.getSheets() + somePad.getSheets());
d) Add a statement to the driver class that tears off one sheetfrom the object somePad.somePad.tearOff();
e) Add a new method to the PaperPad class called totalThickness.This method should take no parameters, and should return the totalthickness of the calling PaperPad object. Now write a statementthat prints to the console the total thickness of the objectsomePad.
//Add this method to the PaperPad class.
public double totalThickness() {
return thickness * sheets;
}
System.out.println(somePad.totalThickness());
Explanation / Answer
The code appears to be correct - put it in a main() method and run it.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.