Velocity Reviews > Java > Help with an assignment

# Help with an assignment

Lew
Guest
Posts: n/a

 02-18-2007
James Bryan Chua wrote:
> In no way, was I trying to get anyone to give me the answer.. I really
> want to learn to program well and was just stuck on this problem..
> I've figured out how to make a left justified triangle by prompting
> for input n and using a for loop where i < n to print out "[]" *(i+1).
> Now, I'm just unsure how to do it where the triangle is centered and
> right justified. Any advice? Thank you.

As Patricia suggests frequently, step back from the computer and think about
the problem, what it actually means, and what steps you would have to follow
using paper and pen[cil] to step through the algorithm.

So you have to ask yourself,
- What is a "triangle"? You partially answered this in your first draft.
- What is "centered"? (Hint: "centered" implies a notion of total width.)
- What is "right justified"?
- In each case, what would the program output look like? Actually draw a picture.
- What out of a computer onto a screen, paper or other output medium would
make pictures at least approximately like that?
- What are the output commands that would produce such pictures?
- What data are needed by these commands in order to get it right?

- Lew

Alex Hunsley
Guest
Posts: n/a

 02-18-2007
Patricia Shanahan wrote:
> Alex Hunsley wrote:
>> James Bryan Chua wrote:
>>> Alright I'm having a bit of trouble getting started for this
>>> assignment in my Java class.

>> [snip description]
>>
>> Shame that! Did you actually have a question for us?
>>
>> Did you try the exercise? How far did you get? What happened?

>
> The quoted sentence says "I'm having a bit of trouble getting started"
> so I assume he did not get very far, and needs advice on how to get
> started, which I sent in my first response.

Fair enough. It just looked like another hopeful "maybe if I post my
homework question someone will just write the solution for me" type of post.

Alex Hunsley
Guest
Posts: n/a

 02-18-2007
James Bryan Chua wrote:
> On Feb 18, 12:04 pm, Patricia Shanahan <(E-Mail Removed)> wrote:
>> John wrote:
>>> Patricia Shanahan wrote:
>>>> Alex Hunsley wrote:
>>>>> James Bryan Chua wrote:
>>>>>> Alright I'm having a bit of trouble getting started for this
>>>>>> assignment in my Java class.
>>>>> [snip description]
>>>>> Shame that! Did you actually have a question for us?
>>>>> Did you try the exercise? How far did you get? What happened?
>>>> The quoted sentence says "I'm having a bit of trouble getting started"
>>>> so I assume he did not get very far, and needs advice on how to get
>>>> started, which I sent in my first response.
>>>> Patricia

>> I don't see that we do. Remember the objective is to help the OP get
>> started, not to do the assignment for him.
>>
>> Patricia

>
> In no way, was I trying to get anyone to give me the answer.. I really
> want to learn to program well and was just stuck on this problem..
> I've figured out how to make a left justified triangle by prompting
> for input n and using a for loop where i < n to print out "[]" *(i+1).
> Now, I'm just unsure how to do it where the triangle is centered and
> right justified. Any advice? Thank you.

Ah, much better...

We have a much better idea of how to help people if they say exactly how
far they've got, and what problems they might now be having. Now we know
you're not just hoping for a readymade solution to be dropped on your
lap like some other people are!

So, doing a few sketches on paper of the various example would be a good
idea, as others have suggested, and Patricia's advice is good.
A hint: you might want to be outputting some space characters (' ')
before things in order to get visible characters like '[]' to appear
more to the right of the screen...

lex

James Bryan Chua
Guest
Posts: n/a

 02-18-2007
On Feb 18, 2:41 pm, Alex Hunsley <(E-Mail Removed)> wrote:
> James Bryan Chua wrote:
> > On Feb 18, 12:04 pm, Patricia Shanahan <(E-Mail Removed)> wrote:
> >> John wrote:
> >>> Patricia Shanahan wrote:
> >>>> Alex Hunsley wrote:
> >>>>> James Bryan Chua wrote:
> >>>>>> Alright I'm having a bit of trouble getting started for this
> >>>>>> assignment in my Java class.
> >>>>> [snip description]
> >>>>> Shame that! Did you actually have a question for us?
> >>>>> Did you try the exercise? How far did you get? What happened?
> >>>> The quoted sentence says "I'm having a bit of trouble getting started"
> >>>> so I assume he did not get very far, and needs advice on how to get
> >>>> started, which I sent in my first response.
> >>>> Patricia
> >> I don't see that we do. Remember the objective is to help the OP get
> >> started, not to do the assignment for him.

>
> >> Patricia

>
> > In no way, was I trying to get anyone to give me the answer.. I really
> > want to learn to program well and was just stuck on this problem..
> > I've figured out how to make a left justified triangle by prompting
> > for input n and using a for loop where i < n to print out "[]" *(i+1).
> > Now, I'm just unsure how to do it where the triangle is centered and
> > right justified. Any advice? Thank you.

>
> Ah, much better...
>
> We have a much better idea of how to help people if they say exactly how
> far they've got, and what problems they might now be having. Now we know
> you're not just hoping for a readymade solution to be dropped on your
> lap like some other people are!
>
> So, doing a few sketches on paper of the various example would be a good
> idea, as others have suggested, and Patricia's advice is good.
> A hint: you might want to be outputting some space characters (' ')
> before things in order to get visible characters like '[]' to appear
> more to the right of the screen...
>
> lex

I think I've figured out how to do the right justified one, but I'm
still pretty stumped by the center justified one. I could do the same
for loop that I did with the other one but add a " " * n --

James Bryan Chua
Guest
Posts: n/a

 02-18-2007
On Feb 18, 2:37 pm, Alex Hunsley <(E-Mail Removed)> wrote:
> Patricia Shanahan wrote:
> > Alex Hunsley wrote:
> >> James Bryan Chua wrote:
> >>> Alright I'm having a bit of trouble getting started for this
> >>> assignment in my Java class.
> >> [snip description]

>
> >> Shame that! Did you actually have a question for us?

>
> >> Did you try the exercise? How far did you get? What happened?

>
> > The quoted sentence says "I'm having a bit of trouble getting started"
> > so I assume he did not get very far, and needs advice on how to get
> > started, which I sent in my first response.

>
> Fair enough. It just looked like another hopeful "maybe if I post my
> homework question someone will just write the solution for me" type of post.

I think I've figured out how to do the right justified one, but I'm
still pretty stumped by the center justified one. I could do the same
for loop that I did with the other one but add a " " * n --

Lew
Guest
Posts: n/a

 02-18-2007
James Bryan Chua wrote:
> I think I've figured out how to do the right justified one, but I'm
> still pretty stumped by the center justified one. I could do the same
> for loop that I did with the other one but add a " " * n --

How far into a line is its center?

- Lew

James Bryan Chua
Guest
Posts: n/a

 02-18-2007
On Feb 18, 4:36 pm, Lew <(E-Mail Removed)> wrote:
> James Bryan Chua wrote:
> > I think I've figured out how to do the right justified one, but I'm
> > still pretty stumped by the center justified one. I could do the same
> > for loop that I did with the other one but add a " " * n --

>
> How far into a line is its center?
>
> - Lew

Depends on how many rows the user inputs..

Lew
Guest
Posts: n/a

 02-18-2007
James Bryan Chua wrote:
>>> I think I've figured out how to do the right justified one, but I'm
>>> still pretty stumped by the center justified one. I could do the same
>>> for loop that I did with the other one but add a " " * n --

Lew wrote:
>> How far into a line is its center?

James Bryan Chua wrote:
> Depends on how many rows the user inputs..

Isn't a row the same thing as a line?

My question has to do with each separate line of output. For example, let us
say you had a line like this (not part of a triangle):

^blah.didi.rightHere!!thereItIs.blaa.ahha.\$

where '^' represents the beginning of the line and is not meant to represent a
literal character, and likewise '\$' represents the end of line, not a literal
character.

Where is the center of that line?

What if it had spaces in it instead of some of the other characters?

What if it had spaces in it in lieu of any other character?

- Lew

Mark Space
Guest
Posts: n/a

 02-20-2007
James Bryan Chua wrote:
> On Feb 18, 4:36 pm, Lew <(E-Mail Removed)> wrote:
>> James Bryan Chua wrote:
>>> I think I've figured out how to do the right justified one, but I'm
>>> still pretty stumped by the center justified one. I could do the same
>>> for loop that I did with the other one but add a " " * n --

>> How far into a line is its center?
>>
>> - Lew

>
> Depends on how many rows the user inputs..
>
>
>

Hint: Ignoring "characters" for now, how would you normally find the
midpoint of a line? Isn't the midpoint the same as it's "center?"