Quiz 2 Solutions

Quiz 2 Solutions - +getCapacity() : int +getContents() : int

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Computer Science 302 Section 3 Week 3 Quiz Solutions 2006-09-22 Name: 1 (5 points) Draw a memory diagram that represents the local variables, their contents, and the objects they point to after the following block of code has executed. Assume that the garbage collector has not had a chance to pick up any unused objects. Inside the memory box for each object, be sure to record the values of its member variables. Use the following UML diagram as a reference for the Cup class, which represents a simple measuring cup that has a total capacity (measured in eighths of a pint) and a current amount of water that it contains. Cup - capacity : int - contents : int +Cup(int capacity, int initialContents)
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: +getCapacity() : int +getContents() : int +getRemainingCapacity() : int +pourInto(int amount) +pourOut(int amount) Cup cupA = new Cup(5,5); Cup cupB = new Cup(3,1); double amountInB = cupB.getContents(); cupA.pourOut(4); cupB.pourInto(2); double totalSpareCapacity = cupA.getRemainingCapacity() + cupB.getRemainingCapacity(); double totalContents = cupA.getContents() + cupB.getContents(); cupA cupB amountInB 1 totalSpareCapacity 4 totalContents 4 capacity:5 contents:1 Cup capacity:3 contents:3 Cup The proper values for variables (including pointers to objects and their member variable values) were worth 1 point each....
View Full Document

This note was uploaded on 03/30/2008 for the course CS 302 taught by Professor Willbenton during the Fall '07 term at Wisconsin.

Ask a homework question - tutors are online