CS100, Spring 2000, Exercise 5: Don't Box Me In! Due at the beginning of lecture on Tuesday, March 7 Name: ____________________________________________________________________ ID: ____________ Concepts + Class definitions, objects, references, null, instance variables. + Declaration versus initialization versus instantiation/allocation. + Box diagrams. What to turn in: A printout of this exercise with your answers legibly HANDWRITTEN. =============================================================================== (a) Fill in the blanks and boxes below to match the comments. // REFER TO PROJECT 4 ON THE CS100 WEBSITE! // For this exercise, you're using a miniature version of Project 4's // $Parthon$. Although on Project 4 you will want to use multiple variables, // create this family tree without using any more variables. Each // $Parthon$ now has only a $name$ and a $parent$: class Parthon { ________________________________________ ; // name of the Parthon ________________________________________ ; // parent of the Parthon } public class Exercise5 { public static void main(String[] args) { // The following declaration provides the only variable we // want you to use: Parthon ur; // Create this family tree without using any more variables // // Ani // | // | // Naj // | // | // Ur // // So, your code will have no $Ani$ or $Naj$ variables! // HINT: $ur.parent$ should prove useful at some point +-----------------------------------------------------------------+ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | +-----------------------------------------------------------------+ // ******* draw the Box diagram for this point in the program ******* // (See Part b for an explanation of what you need to do.) } // method main } // class Parthon =============================================================================== (b) Draw the requested box diagram for the state of the computer at the *precise* point specified above in Part a. We have already drawn for you all the String objects that are needed. class Exercise5 class Parthon +---------------+ +---------------------------------------------------------+ | | | | | main(args) | | | | +---------+ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | +---------+ | | | | | | | +---------------+ | | | | class String | | +---------------+ | | | | | | | "Ur" | | | | | | | | "Naj" | | | | | | | | "Ani" | | | | | | | +---------------+ | | | | | | | | +---------------------------------------------------------+