Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help: I need to write an applet that displays a triangle on top of a rect

ID: 3655591 • Letter: P

Question

Please help: I need to write an applet that displays a triangle on top of a rectangle, to make it look like a pine tree. I have most of the it, just can't seem to get the correct coordinates. package pinetree; import javax.swing.JApplet; import java.awt.Color; import java.awt.Graphics; public class PineTree extends JApplet { private int[] xTree = {50, 50, 150}; private int[] yTree = {50, 200, 200}; private int[] xTrunk = {100, 90, 50, 90}; private int[] yTrunk = {100, 100, 200, 200}; public void paint(Graphics canvas) { this.setBackground(Color.WHITE); canvas.setColor(Color.GREEN); canvas.fillPolygon(xTree, yTree, xTree.length); canvas.setColor(Color.GRAY); canvas.fillPolygon(xTrunk, yTrunk, xTrunk.length); } }

Explanation / Answer

class PrintTree { public static void main (String[] args) { int treeHeight, height, spaces, rows, trunk; int segment; int widestBit=1; int baseSize; int numStars; // Get the height of the tree System.out.print("Enter a number: "); //method to get stuff from keyboard>; for(int i=1; i