Isopen false public candyboxstring n int x name n

This preview shows page 12 - 17 out of 17 pages.

isOpen = false; } public CandyBox(String n, int x) { name = n; numCandies = x; isOpen = false; } public void dispense() { if (isOpen) { numCandies = numCandies - 5; } } public void open() { isOpen = true; } public String toString() { return name + " " + isOpen + " " + numCandies; } } Two objects of type CandyBox are created as follows: CandyBox c1 = new CandyBox(); CandyBox c2 = new CandyBox(new String("Pebbles"), 50); Complete the diagram below illustrating the values that are stored in the instance variables for each of these objects. You should write very clearly on the diagram, as you are required to change the diagram when you complete part (b) of this question.
Image of page 12

Subscribe to view the full document.