CS 310, Object-Oriented Programming with Java

Quiz 10, 3 April 2008


  1. Assuming the screen size is sw units wide by sh units high, show the calculations necessary to create a window 1/3 the screen size centered on the screen. You don't have to show any code, but make sure you show all the calculations necessary to call the code.


    A window (or frame) is specified by the coordinates of its upper-left corner (xw, yw) and its height (hw) and width (ww). The window height and width should be a third of the corresponding screen dimensions:

    wh = sh/3
    ww = sw/3
    The screen center's at (sw/2, sh/2); the window center's at (xw + ww/2, yw + wh/2)). Those two points should be the same, which gives
    xw + ww/2 = sw/2
    yw + wh/2 = sh/2
    which rewrites to
    xw = sw/2 - ww/2
    yw = sh/2 - wh/2
    See page 253 (7th ed.) or 290 (8th ed.).

  2. Outline the structure used to implement the class relations in the Point2D classes. Don't use any more syntax than
    blah class blah { blah }
    but make sure what syntax you do use is complete enough to show the relations.


    Point2D is a parent abstract class for the two concrete classes Point2D.Float and Point2D.Double. The interesting part about the parent-child relation is that the children are static inner classes of the parent (page 262 (7th ed.) or 300 (8th ed.)):

    public class 
    Point2D {
    
      public static class
      Point2D.Float 
      extends Point2D {
        }
    
      public static class
      Point2D.Double 
      extends Point2D {
        }
      }
    


This page last modified on 31 March 2008.