Help with an assignment

Discussion in 'Java' started by James Bryan Chua, Feb 18, 2007.

  1. Alright I'm having a bit of trouble getting started for this
    assignment in my Java class. I have to create a class that prompts for
    how many rows are in a triangle and print the output with an
    equilateral triangle where the top row is centered and comes down as
    if it was center justified-- and also a triangle as if it were right
    justified. Thanks in advance for your help.
    James Bryan Chua, Feb 18, 2007
    #1
    1. Advertising

  2. James Bryan Chua wrote:
    > Alright I'm having a bit of trouble getting started for this
    > assignment in my Java class. I have to create a class that prompts for
    > how many rows are in a triangle and print the output with an
    > equilateral triangle where the top row is centered and comes down as
    > if it was center justified-- and also a triangle as if it were right
    > justified. Thanks in advance for your help.
    >


    I have some general advice on getting started on assignments at
    http://home.earthlink.net/~patricia_shanahan/beginner.html

    For tasks like the triangle drawing, it can be helpful to try to do the
    task yourself, and see what you have to do.

    Patricia
    Patricia Shanahan, Feb 18, 2007
    #2
    1. Advertising

  3. James Bryan Chua wrote:

    > Thanks in advance for your help.


    You haven't specified, what your problem is. That way nobody
    can help you in another way than wishing you luck.


    Regards, Lothar
    --
    Lothar Kimmeringer E-Mail:
    PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

    Always remember: The answer is forty-two, there can only be wrong
    questions!
    Lothar Kimmeringer, Feb 18, 2007
    #3
  4. James Bryan Chua

    Alex Hunsley Guest

    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?
    Alex Hunsley, Feb 18, 2007
    #4
  5. 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
    Patricia Shanahan, Feb 18, 2007
    #5
  6. James Bryan Chua

    John Guest

    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

    OP - We need more information...

    For example the number must be 3 or greater. Are you doing any kind of
    error checking?

    What are you using for a row element>? "*" or "x" or somthing?
    Do you have an algorithm for determining how many "*"s you need? I
    think you will need something to help you figure out how many you need.
    John, Feb 18, 2007
    #6
  7. On Feb 19, 2:47 am, John <> wrote:
    ...
    > OP - We need more information...


    No we don't. Or rather, the best help
    the OP can get at the moment is the
    advice (and link) that Patricia has
    already given.

    The OP will not get very far with
    programming, if they come to rely
    on people who spoon-feed the answers.

    Andrew T.
    Andrew Thompson, Feb 18, 2007
    #7
  8. 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

    > OP - We need more information...
    >


    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
    Patricia Shanahan, Feb 18, 2007
    #8
  9. On Feb 18, 12:04 pm, Patricia Shanahan <> 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

    > > OP - We need more information...

    >
    > 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.
    James Bryan Chua, Feb 18, 2007
    #9
  10. James Bryan Chua

    John Guest

    Patricia Shanahan 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

    >>
    >> OP - We need more information...
    >>

    >
    > 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

    Which is exactly what *I* was trying to do. And since there's no way I
    could possibly code a solution to the problem without asking for /
    looking for help, I tried to supply a starting point.
    John, Feb 18, 2007
    #10
  11. James Bryan Chua

    Lew Guest

    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
    Lew, Feb 18, 2007
    #11
  12. James Bryan Chua

    Alex Hunsley Guest

    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, Feb 18, 2007
    #12
  13. James Bryan Chua

    Alex Hunsley Guest

    James Bryan Chua wrote:
    > On Feb 18, 12:04 pm, Patricia Shanahan <> 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
    >>> OP - We need more information...

    >> 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
    Alex Hunsley, Feb 18, 2007
    #13
  14. On Feb 18, 2:41 pm, Alex Hunsley <> wrote:
    > James Bryan Chua wrote:
    > > On Feb 18, 12:04 pm, Patricia Shanahan <> 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
    > >>> OP - We need more information...
    > >> 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, Feb 18, 2007
    #14
  15. On Feb 18, 2:37 pm, Alex Hunsley <> 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 --
    James Bryan Chua, Feb 18, 2007
    #15
  16. James Bryan Chua

    Lew Guest

    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
    Lew, Feb 18, 2007
    #16
  17. On Feb 18, 4:36 pm, Lew <> 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..
    James Bryan Chua, Feb 18, 2007
    #17
  18. James Bryan Chua

    Lew Guest

    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
    Lew, Feb 18, 2007
    #18
  19. James Bryan Chua

    Mark Space Guest

    James Bryan Chua wrote:
    > On Feb 18, 4:36 pm, Lew <> 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?"
    Mark Space, Feb 20, 2007
    #19
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. itsme
    Replies:
    1
    Views:
    1,614
    Ralf Hildebrandt
    Jul 23, 2003
  2. ra
    Replies:
    3
    Views:
    3,011
    Egbert Molenkamp
    Aug 4, 2004
  3. nagy
    Replies:
    36
    Views:
    979
    Terry Reedy
    Jul 20, 2006
  4. Chris
    Replies:
    34
    Views:
    1,480
  5. isaac2004
    Replies:
    4
    Views:
    356
    =?UTF-8?B?RXJpayBXaWtzdHLDtm0=?=
    Oct 4, 2007
Loading...

Share This Page