Help with an assignment

J

James Bryan Chua

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

Patricia Shanahan

James said:
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
 
L

Lothar Kimmeringer

James said:
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: (e-mail address removed)
PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

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

Alex Hunsley

James said:
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?
 
P

Patricia Shanahan

Alex said:
James said:
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
 
J

John

Patricia said:
Alex said:
James said:
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.
 
A

Andrew Thompson

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

Patricia Shanahan

John said:
Patricia said:
Alex said:
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
 
J

James Bryan Chua

John said:
Patricia said:
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.
 
J

John

Patricia said:
John said:
Patricia said:
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.
 
L

Lew

James said:
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
 
A

Alex Hunsley

Patricia said:
Alex said:
James said:
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.
 
A

Alex Hunsley

James said:
John said:
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
 
J

James Bryan Chua

James said:
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 --
 
J

James Bryan Chua

Patricia said:
Alex said:
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 --
 
L

Lew

James said:
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
 
L

Lew

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
 
M

Mark Space

James said:
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?"
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top