• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Fence Builder program

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I feel like an idiot. I have no idea.
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We've all been there.  How about something like this:
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79253
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
I'd appreciate it if you pronounced my name correctly. Pinhead, with a silent "H". Petite ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic