Question: Project 5 - Develop a Java program that Uses selection constructs (if, and if else). Uses the Java iteration constructs (while, do, for). Uses static

Project 5 - Develop a Java program that

Uses selection constructs (if, and if else).

Uses the Java iteration constructs (while, do, for).

Uses static variables.

Ensure integer variables input are within a range that will not cause integer overflow.

Uses proper design techniques including reading UML Class Diagrams.

1)Develop a Fence class:

a.Fence structure

i.The frame of the fence is represented by pound sign (#).

ii.The fence bars are represented by vertical bar character or pipe, as it is called. (pipe is above the back splash on most keyboards).

iii.Place one space to left and right of the fence bars.

iv.See sample run below.

b.fenceCount a static integer variable that represents the number of fence object created in a given run of the program.

c.Instance variables

i.height an integer representing the height of the fence

ii.width an integer representing the width of the fence

d.Constructors - Default (no parameter constructor)

i.sets the instance variables and static variable to zero

ii.Note the program will use mutator methods to change fences height and width to values other than zero.

e.Methods

i.getHeight returns the fences height.

ii.getWidth returns the fences width

iii.setHeight (int newHeight)

1.Changes the value of the fences height

2.Ensures the height is within a range of 2 to 5.

3.Returns a boolean

a.true indicating height is within range and height is set to parameter value.

b.false indicating height not in range and height instance variable unchanged.

iv.setWidth (int newWidth)

1.Changes the value of the fences width

2.Ensures the height is within a range of 3 to 24.

3.Returns a boolean

a.true indicating width is within range and width is set to parameter value.

b.false indicating height not in range and height instance variable unchanged.

v.getFenceCount returns the value of the fenceCount static variable.

vi.draw

1.Uses the width and height instance variable to draw a fence of the appropriate size.

2.Increments the fenceCount variable.

2)Create a FenceBuilder class to draw fences.

a.Creates a fence object

b.Prompt user to enter the height, include heights range in prompt.

c.Calls the setHeight on the fence objects .

i.If the returned boolean value of the setHeight method is false

1.Display an error message that the height is not within range

2.Returns to step 2b and prompt for a new height value.

d.Calls the setWidth on the fence objects

i.If the returned boolean value of the setWidth method is false

1.Display an error message that the width is not within range

2.Returns to step 2d and prompt for a new width value

e.Calls the draw on the fence object method display the fence.

f.Prompts the user if they would like to draw another fence.

i.if so return to step 2b.

ii.if not continue

g.Call the getFenceCount method to display the number of fences created by in a statement such as, There were 5 fences drawn.

.

3)Below is the UML diagram of Fence class.

-----------------------------------------------------------------------------

Fence

height : int

width : int

static fenceCount : int

Fence()

Fence (int, int)

getHeight():int

setHeight(int newHeight)

getWidth(): int

setWidth(int newWidth)

getFenceCount():int

draw()

-------------------------------------------------------------------------

Sample Run

Enter height in range [2, 5]: 6

Height must be between 2 and 5.

Enter height in range [2, 5]: 3

Enter width. [3, 24]: 10

##########

# | | | | | | | | |#

##########

Do you want to draw another fence? [Y or N]: y

Enter height in range [2, 5]: 4

Enter width. [3, 24]: 27

Width must be between 3 and 24.

Enter width. [3, 24]: 24

########################

# | | | | | | | | | | | | | | | | | | | | | | | | |#

# | | | | | | | | | | | | | | | | | | | | | | | | |#

########################

Do you want to draw another fence? [Y or N]: n

You built 2 fences.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!