Question
Programming Project #5 Project Outcomes: Develop a Java program that Uses selection constructs (if, and if else). Uses the Java iteration constructs (while, do, for).
Programming Project #5
Project Outcomes:
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
Background Information:
The Unified Modeling Language (UML) provides a useful notation for designing and developing object-oriented software systems. One of the basic components of the UML is a class diagram, which are used to depict the attributes and behaviors of a class. A basic class diagram (as shown in the figure below) has three components. The first is the class name. The second component includes the class's attributes or fields. Each attribute is followed by a colon (:) and its data type. The third component includes the class's behaviors or methods. If the method takes parameters, their types are included in parentheses. Each behavior is also followed by a colon (:) and its return type. If the return value of a method is void, the return type can be omitted. The + and - sign indicates the public and private modifiers. For more information on the UML, refer to http://www.uml.org/.
Project Requirements:
Fence class:
How a Fence is displayed on screen
The frame of the fence is represented by pound sign (#).
The fence bars are represented by vertical bar character or pipe (|), as it is called. (pipe is above the back splash on most keyboards).
Place one space to left and right of the fence bars.
See sample run below.
fenceCount a static integer variable that represents the number of fence object created in a given run of the program.
Instance variables
height an integer representing the height of the fence
width an integer representing the width of the fence
Constructors - Default (no parameter constructor)
sets the instance variables and static variable to zero
Note the program will use mutator methods to change fences height and width to values other than zero.
Methods
getHeight returns the fences height.
getWidth returns the fences width
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, true if height is set correctly, false if height value is not valid
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, true if height is set correctly, false if height value is not valid
getFenceCount returns the value of the fenceCount static variable.
draw - 1) Uses the width and height instance variable to draw a fence of the appropriate size; 2) Increments the fenceCount variable.
Hints:
This class never print anything to the screen except in the draw method
FenceBuilder class
Creates a fence object
Prompt user to enter the height and width.
Calls the setHeight on the fence objects.
If the returned boolean value of the setHeight method is false, display an error message that the height is not within range and prompt for a new height value.
Calls the setWidth on the fence objects
If the returned boolean value of the setWidth method is false, display an error message that the width is not within range and prompt for a new width value.
Calls the draw on the fence object method display the fence on screen.
Prompts the user if they would like to draw another fence. If yes repeat the procedure starting from step 2 to 6. If no, proceed to step 7.
Call the getFenceCount method to display the number of fences created so far in a statement such as, There were 5 fences drawn.
UML diagrams for fence diagram
Fence ------------ - height : int - width : int - static fenceCount : int ------------ + Fence() + Fence(int, int) + getHeight():int + setHeight(int):boolean + getWidth():int + setWidth(int):boolean + getFenceCount():int + draw()
Interactive Sample Run (you will see this if you run in jGrasp or command line)
Enter height in range [2, 5]: 6 Height must be between 2 and 5. Enter height in range [2, 5]: 3 Enter width in range [3, 24]: 10 ########## #||||||||# ########## Do you want to draw another fence? [Y or N]: y Enter height in range [2, 5]: 4 Enter width in range [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.
Input to be used in zylab
6 3 y 4 27 24 n
Submission Requirements:
Your project should follow the instructions below. Any submissions that do not follow the stated requirements will not be graded.
Follow the submission requirements of your instructor.
You should have the following files for this assignment:
Fence.java,
FenceBuilder.java.
Remember to compile and run your program one last time before you submit it.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started