Programming Project #5 Project Outcomes: Develop a Java program that Uses select
ID: 3705718 • Letter: P
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).
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 fence’s height and width to values other than zero.
Methods
getHeight – returns the fence’s height.
getWidth – returns the fence’s width
setHeight(int newHeight) - 1) Changes the value of the fence’s 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 fence’s 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
Interactive Sample Run (you will see this if you run in jGrasp or command line)
Input to be used in zylab
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.
Explanation / Answer
Hi Dear,
Please find my implementation.
Please let me know in case of any issue.
Output:
Enter height in range [2, 5]:
4
Enter width. [3, 24]:
6
######
#||||#
#||||#
######
Do you want to draw another fence?
[Y or N]:
n
You built 1 fences.
Process finished with exit code 0
Please DONT forgot to rate my answer. We are working hard for you Guys!!
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.