Foliage

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.

Answer:

  • X: 200
  • Y: 45
  • width: 125
  • height: 55

Foliage

Define these values as constants:

final int treeX = 200, treeY = 45, treeW = 125, treeH = 55;  // tree leaves

Add foliage to the tree:

gr.setColor( Color.green );
gr.fillOval( treeX, treeY, treeW, treeH );

fillOval() is like drawOval(), except that it fills the figure with the current color.

Four green lines make up the rolling hills in the background. (Click here to see them.) Estimate an (X, Y) value for each line's endpoints. If a value already has a name, like houseX, or can be calculated, do that.

QUESTION 7:

The first line is the one on the left. Fill in the blanks in the following. (It might be a bit tedious to fill them all in, but try at least a few.)

 startX startY endX endY
line 1L1X1: _______L1Y1:_______L1X2:_________L1Y2:
line 2L2X1: _______L2Y1:_______L2X2:_________L2Y2: _______
line 3L3X1: _______L3Y1:_______L3X2:_________L3Y2: _______
line 4L4X1: _______L4Y1:_______L4X2:_________L4Y2: _______