Question

Programming Project #5 Project Outcomes: Develop a Java program that Uses selection constructs (if, and if...

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

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.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Drop me a comment in case of any concern.

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

public class Fence {

public static int fenceCount;

private int height;

private int width;

public Fence()

{

this.fenceCount=0;

this.height=0;

this.width=0;

}

public Fence(int ht, int wt)

{

setHeight(ht);

setWidth(wt);

}

public int getHeight() {

return height;

}

public void setHeight(int height) {

this.height = height;

}

public int getWidth() {

return width;

}

public void setWidth(int width) {

this.width=width;

}

public static int getFenceCount()

{

return fenceCount;

}

public void draw()

{

fenceCount++;

for(int i=1;i<=height;i++)

{

for(int j=1; j<=width;j++)

{

if(i==1||i==height)

{

System.out.print("#");

}

else if(j==1||j==width)

{

System.out.print("#");

}

else{

System.out.print("|");

}

}

System.out.println(" ");

}

}

}

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

import java.util.Scanner;

public class FenceBuilder {

public static void main(String[] args) {

int ht,wt;

String choice;

Scanner sc = new Scanner(System.in);

do{

boolean temp=false;

do{

System.out.println("Enter height in range [2, 5]: ");

ht = sc.nextInt();

if(ht<=5 && ht>=2)

temp=true;

else

{

System.out.println("Height must be between 2 and 5.\n");

temp=false;

}

}while(!temp);

do{

System.out.println("Enter width. [3, 24]: ");

wt = sc.nextInt();

if(wt<=24 && wt>=3)

temp=true;

else

{

System.out.println("Width must be between 3 and 24.\n");

temp=false;

}

}while(!temp);

  

Fence f = new Fence(ht,wt);

f.draw();

System.out.println("Do you want to draw another fence? ");

System.out.println("[Y or N]:");

choice=sc.next();

}while(choice.equalsIgnoreCase("Y"));

System.out.println("You built "+ Fence.getFenceCount() +" fences.");

}

}

Output:

R Problem s @Javadoc 다 Declaration貝Console X 貵Debug <terminated> FenceBuilder [Java Application] C:Program FilesJava\jdk1.8.0

Add a comment
Know the answer?
Add Answer to:
Programming Project #5 Project Outcomes: Develop a Java program that Uses selection constructs (if, and if...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Amusement Park Programming Project Project Outcomes Use the Java selection constructs (if and if else). Use...

    Amusement Park Programming Project Project Outcomes Use the Java selection constructs (if and if else). Use the Java iteration constructs (while, do, for). Use Boolean variables and expressions to control iterations. Use arrays or ArrayList for storing objects. Proper design techniques. Project Requirements Your job is to implement a simple amusement park information system that keeps track of admission tickets and merchandise in the gift shop. The information system consists of three classes including a class to model tickets, a...

  • I need help with my java code i am having a hard time compiling it //...

    I need help with my java code i am having a hard time compiling it // Cristian Benitez import java.awt.Color; import java.awt.Graphics; import java.util.ArrayList; import javax.swing.JPanel; Face class public class FaceDraw{ int width; int height; int x; int y; String smileStatus; //default constructor public FaceDraw(){ } // Getters and Setters for width,height,x,y public int getWidth(){ return width; } public void setWidth(int width){ this.width=width; } public int getHeight(){ return height; } public void setHeight(int height){ this.height=height; } public int getX(){ return...

  • Programming Project 3 See Dropbox for due date Project Outcomes: Develop a Java program that uses:...

    Programming Project 3 See Dropbox for due date Project Outcomes: Develop a Java program that uses: Exception handling File Processing(text) Regular Expressions Prep Readings: Absolute Java, chapters 1 - 9 and Regular Expression in Java Project Overview: Create a Java program that allows a user to pick a cell phone and cell phone package and shows the cost. Inthis program the design is left up to the programmer however good object oriented design is required.    Project Requirements Develop a text...

  • In Java please! Problem You will be using the point class discussed in class to create...

    In Java please! Problem You will be using the point class discussed in class to create a Rectangle class. You also need to have a driver class that tests your rectangle. Requirements You must implement the 3 classes in the class diagram below and use the same naming and data types. Following is a description of what each method does. Point Rectangle RectangleDriver - x: int - top Left: Point + main(args: String[) - y: int - width: int +...

  • java language please. thank you T-Mobile 9:00 AM For this assignment, create a Java class named...

    java language please. thank you T-Mobile 9:00 AM For this assignment, create a Java class named "MyRectangle3d" Your class must have the following attributes or variables · x (the x coordinate of the rectangle, an integer) * y (the y coordinate of the rectangle, an integer) * length (the length of the rectangle, an integer) * width (the width of the rectangle, an integer) * height (the height of the rectangle, an integer) * color( the color of the rectangle,...

  • Write Java program( see IncomeTaxClassTemplate) uses a class( TaxTableToolTemplate), which has a tax table built in....

    Write Java program( see IncomeTaxClassTemplate) uses a class( TaxTableToolTemplate), which has a tax table built in. The main method prompts for a salary, then uses a TaxTableTools method to get the tax rate. The program then calculates the tax to pay and displays the results to the user. Run the program with annual salaries of 10000, 50000, 50001, 100001 and -1 (to end the program) and note the output tax rate and tax to pay. a. Modify the TaxTableTools class...

  • I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that a...

    I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that accepts one integer parameter and returns the value raised to the third power as an integer. o Write a method called randominRange that accepts two integer parameters representing a range. The method returns a random integer in the specified range inclusive. 2. o Write a method...

  • JAVA design a class named Rectangle to represent a rectangle. The class contains: A method named getPerimeter() that returns the perimeter. Two double data fields named width and height that specify...

    JAVA design a class named Rectangle to represent a rectangle. The class contains: A method named getPerimeter() that returns the perimeter. Two double data fields named width and height that specify the width and height of the rectangle. The default values are 1 for both width and height. A no-arg constructor that creates a default rectangle. A constructor that creates a rectangle with the specified width and height. A method named getArea() that returns the area of this rectangle. design...

  • CompSci 251: Intermediate Computer Programming Spring 2017 -Java Lab 5 For this lab we will be...

    CompSci 251: Intermediate Computer Programming Spring 2017 -Java Lab 5 For this lab we will be looking at static, or class variables. Remember that where instances variables are associated with a particular instance, static variables are associated with the particular class. Specifically, if there are n instances of a class, there are n copies of an instance variable, but exactly one copy of a static variable (even when n = 0). Student - uniqueId : int - id: int -...

  • this is for java programming Please Use Comments I am not 100% sure if my code...

    this is for java programming Please Use Comments I am not 100% sure if my code needs work, this code is for the geometric if you feel like you need to edit it please do :) Problem Description: Modify the GeometricObject class to implement the Comparable interface and define a static max method in the GeometricObject class for finding the larger (in area) of two GeometricObject objects. Draw the UML and implement the new GeometricObject class and its two subclasses...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT