Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Tree Structures (Nested loops) Summary Write a program that draws two trce like structures-- a flat rectangular shaped tree and an Xmas style tree The

image text in transcribed
image text in transcribed
Tree Structures (Nested loops) Summary Write a program that draws two trce like structures-- a flat rectangular shaped tree and an Xmas style tree The program TreeStructures.java asks the user for the height of a tree and uses the height information to draw the trees. It draws a rectangle triangle to display the top portion of the tree, followed by a rectangle to represent the trunk the tree. Fores, How tell ahoold the top of the trees Fat Tree Put the programs in a3 package. Be sure to suitable constants for your programs Details See the sample outputs below for how your program should perform. Note that it begins by printing out its title and author information. After that it prints a description of what it does. (You can use the same.) Then it asks the user for how tall the tree should be just the canopy (green party at the top. actually). The size needs to be between Sand 20. If the user enters an invalidsize the program objects and ends -- pausing to ensure that the user sees the message. Otherwise the program continues on to draw the tree as seen above). Flat Tree: The first tree consists of a rectangle to represent the branches (top part), and a rectangle to represent the trunk (bottom part) Xmas Tree: The second tree consists of a triangle to represent the branches, and a rectangle to represent the trunk Top part: The rectangle triangle has as many rows as the number the ser entered. The width of the rectangle triangle is one less than twice the height of the tree (for example, the tree of height 5 has a width of 9). In the case of triangle, the base of the top part is right up against the left margin, and each line above it is intented one space further, and is two characters shorter. The result is an isosceles triangle that looks a bit like the top of a spruce or fir tree. Bottom part: The rectangle below is centred under the rectangle for Flat tree) or triangle for Xmas tree). Its height is one more than one fifth of the height of the top part. For example, the rectangle of the tree above has two rows, since 9-5 + 1 is 2. The width of the rectangle is one third of the width of the tree -- but add one if that width comes out even. For example, the triangle of height Slus a width of 9, so the width of the rectangle is that's 9. The tree of height 4. hemevet, has a base of width 7. Its rectangle would be 3 wide fic., 7. 3is2, which is even, so change it to 3). You can check if a number is even by finding its remainder when divided by 2 Even numbers have a remainder of zero. Thus 1 En Lawen 1 2 - 0 Any number that's not even is add The rectangle needs to be indented a certain number of spaces. To get that number, take the width of the top rectangle triangle, subtract the width of the rectangle, and divide by twe. So for the triangle of heights, the number of spaces to indent the rectangle is (9-3)-2, which is 3. For the tree of height 4. indent (7-3) 2 - 2 spaces See below for some sample outputs Sample outputs The following are some of the posible outcomes of running the TreeStructures.java program for 104 Sample outputi: free structures This program peints two tree like structures! Ariate tree and Christmas tree You chochoti the trees will be By Jij Povrancher (A00000000) How tall should the top of the trobe?? Fiat : Xmas Tree

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Refactoring Databases Evolutionary Database Design

Authors: Scott Ambler, Pramod Sadalage

1st Edition

0321774515, 978-0321774514

More Books

Students also viewed these Databases questions

Question

Define performance appraisal.

Answered: 1 week ago