Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2007

Tip: Looking for answers? Try searching our database.

Help with an assignment

Thread view: 
James Bryan Chua - 18 Feb 2007 06:11 GMT
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.
Patricia Shanahan - 18 Feb 2007 07:10 GMT
> 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
Lothar Kimmeringer - 18 Feb 2007 10:54 GMT
> 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
Signature

Lothar Kimmeringer                E-Mail: spamfang@kimmeringer.de
              PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

Always remember: The answer is forty-two, there can only be wrong
                questions!

Alex Hunsley - 18 Feb 2007 11:47 GMT
> 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?
Patricia Shanahan - 18 Feb 2007 15:32 GMT
>> Alright I'm having a bit of trouble getting started for this
>> assignment in my Java class.
[quoted text clipped - 3 lines]
>
> 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
John - 18 Feb 2007 15:47 GMT
>>> Alright I'm having a bit of trouble getting started for this
>>> assignment in my Java class.
[quoted text clipped - 10 lines]
>
> 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.
Andrew Thompson - 18 Feb 2007 17:00 GMT
..
> 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.
Patricia Shanahan - 18 Feb 2007 17:04 GMT
>>>> Alright I'm having a bit of trouble getting started for this
>>>> assignment in my Java class.
[quoted text clipped - 11 lines]
>> 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
James Bryan Chua - 18 Feb 2007 17:48 GMT
> >>>> Alright I'm having a bit of trouble getting started for this
> >>>> assignment in my Java class.
[quoted text clipped - 16 lines]
>
> 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.
Lew - 18 Feb 2007 18:49 GMT
> 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 - 18 Feb 2007 19:41 GMT
>>>>>> Alright I'm having a bit of trouble getting started for this
>>>>>> assignment in my Java class.
[quoted text clipped - 17 lines]
> 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 - 18 Feb 2007 20:28 GMT
> >>>>>> Alright I'm having a bit of trouble getting started for this
> >>>>>> assignment in my Java class.
[quoted text clipped - 32 lines]
>
> 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 --
Lew - 18 Feb 2007 21:36 GMT
> 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 - 18 Feb 2007 21:51 GMT
> > 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
[quoted text clipped - 3 lines]
>
> - Lew

Depends on how many rows the user inputs..
Lew - 18 Feb 2007 22:08 GMT
>>> 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?

> 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 - 20 Feb 2007 22:21 GMT
>>> 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
[quoted text clipped - 4 lines]
>
> 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?"
John - 18 Feb 2007 18:10 GMT
>>>>> Alright I'm having a bit of trouble getting started for this
>>>>> assignment in my Java class.
[quoted text clipped - 17 lines]
>
> 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.
Alex Hunsley - 18 Feb 2007 19:37 GMT
>>> Alright I'm having a bit of trouble getting started for this
>>> assignment in my Java class.
[quoted text clipped - 7 lines]
> 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.
James Bryan Chua - 18 Feb 2007 20:46 GMT
> >>> Alright I'm having a bit of trouble getting started for this
> >>> assignment in my Java class.
[quoted text clipped - 10 lines]
> 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 --


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.