• Post Reply Bookmark Topic Watch Topic
  • New Topic

Fence Builder program  RSS feed

 
Clarence Poma
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I am in the final steps of a project for my Java class. I am, however, having one small issue.

The output needed and shown in the project example for the actual fence drawing with a height of 3 and a width of 10 is:


My output for the drawing aspect is:


Everything else is working fine, but I'm sure that I'm overlooking something simple. Below is my code.

Fence.java:



FenceBuilder.java

 
Clarence Poma
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Quick edit, my needed output was incorrect on the original post. I can't seem to get it aligned on the forum, so I've attached a screenshot of my goal

 
Knute Snortum
Sheriff
Posts: 4210
124
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Do you want the "#" to print every time in the inner loop? (line 62)
 
Clarence Poma
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. I need a border of # symbols, and the rest to be the I symbol. Removing the # gives me the following output:

 
Knute Snortum
Sheriff
Posts: 4210
124
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So if height is 3, when do you need to print all "#"?
 
Clarence Poma
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When the height is 3, I need it to print entirely #s on the 1st and 3rd row. But on the 2nd row, only # on the first and last columns. Example below.

 
Knute Snortum
Sheriff
Posts: 4210
124
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right, so how do you tell the computer to print on the first and third row, keeping in mind that this need to work with a height of five or four or anything else?
 
Clarence Poma
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I feel like an idiot. I have no idea.
 
Knute Snortum
Sheriff
Posts: 4210
124
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We've all been there.  How about something like this:
 
Joree Hubbell
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

 
Junilu Lacar
Sheriff
Posts: 11435
176
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You only showed what's expected for a fence height of 3. That's not enough information though. What would the expected output be for a height of 2? For a height of 5?

We could guess:

Does that look about right?

Also, the graphic you showed does not make sense to me. If I reproduced it the way it would appear using a fixed-width font, it would look different from what your graphic suggests:

That looks wrong to me.
 
Campbell Ritchie
Marshal
Posts: 56227
171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I see you haven't fallen into the trap of making any of your variables static, as happened in last year's post. But if you have a fence 10 yards long, it won't have ten fenceposts; it will either have nine or eleven.
In the setHeight method, don't return anything. Consider whether you should have a setXXX method in the first place; I probably wouldn't. But if you are going to have a setXXX method, you should give it a documentation comment explaining what range it will permit. Don't return false for the wrong range: throw an Exception.It would be better to use constants than those number literals 2 and 5.
Don't write == true or == false which are both poor style and error‑prone if you write = by mistake. And != true looks even worse.
Never
if (b == true) ...
always
if (b) ...
Never
if (b == false) ...
always
if (!b) ...
Some of your variables are poorly names: what does fenceCount mean? And bFence is even harder to understand.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!