Solution to ProgramHeirarchy – Assignment 2

```/*
* File: ProgramHierarchy.java
* Name:
* ---------------------------
* This file is the starter file for the ProgramHierarchy problem.
*/

import acm.graphics.*;
import acm.program.*;
import java.awt.*;

public class ProgramHierarchy extends GraphicsProgram {
// width of the box
private static final int BOX_WIDTH = 175;

//height of the box
private static final int BOX_HEIGHT = 45;

public void run() {

//middle point of the window
double middle = getWidth()/2;

//height window middle
double height_center = getHeight()/2;

//middle of the box itself
double box_mid = BOX_WIDTH/2;

// half the box height
double box_half = BOX_HEIGHT/2;

// base of top square = height_center -40
double base_top= height_center -40 ;

//roof of bottom boxes
double roof_bottom = height_center + 40 ;

/*
* The boxes here
*/

// top rect
GRect top = new GRect(middle-box_mid,base_top -BOX_HEIGHT,BOX_WIDTH,BOX_HEIGHT);

//left rect
GRect left = new GRect(middle/2 -box_mid,roof_bottom,BOX_WIDTH,BOX_HEIGHT);

// mid rect
GRect mid = new GRect(middle-box_mid,roof_bottom,BOX_WIDTH,BOX_HEIGHT);

//right rect
GRect right = new GRect(middle + middle/2 - box_mid,roof_bottom,BOX_WIDTH,BOX_HEIGHT);

/*
* the lines connecting here
*/

//leftLine
GLine leftLine = new GLine(middle/2,roof_bottom,middle,base_top);

//midline
GLine midLine = new GLine(middle,base_top,middle,roof_bottom);

//rightLine
GLine rightLine = new GLine(middle,base_top,middle+middle/2,roof_bottom);

/*
* the labels
*/

// TopLabel
GLabel topLabel = new GLabel("Program");
topLabel.move(middle-topLabel.getWidth()/2, base_top+topLabel.getAscent()/2 -BOX_HEIGHT/2);

//LeftLabel
GLabel leftLabel = new GLabel("GraphicsProgram");
leftLabel.move(middle/2-leftLabel.getWidth()/2, roof_bottom+leftLabel.getAscent()/2+BOX_HEIGHT/2);

//Middle Label
GLabel midLabel = new GLabel("ConsoleProgram");
midLabel.move(middle-midLabel.getWidth()/2, roof_bottom+midLabel.getAscent()/2 +BOX_HEIGHT/2);