Quiz 2 Solutions - getCapacity int getContents int int...

Info icon This 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)
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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern