Help Write Code

A

ashleycantino

Hi there,

I'm new to Java but my instructor doesn't seem to realize it. He
has assigned the following program and I don't even know where to
start. If someone could give me an idea of how to set this up I would
be so grateful!


Chapter 3 #9:
There's an old nursery rhyme that goes like this:
As I was going to St. Ives,
I met a man with seven wives,
Each wife had seven sacks,
Each sack had seven cats,
Each cat had seven kits:
Kits, cats, sacks, and wives,
How many were going to St. Ives?

The last line turns out to be a trick question: only the speaker is
gong to St. Ives; everyone else is presumably heading in the opposite
direction. Suppose however, that you want to find out how many reps of
the assembled multittiude were coming from St. Ives. Write a program
to calculate and display this result. Try to make your program follow
the structure of the problem so that anyone reading your program would
understand what value it is calculating.
 
E

Eric Sosman

Hi there,

I'm new to Java but my instructor doesn't seem to realize it. He
has assigned the following program and I don't even know where to
start. If someone could give me an idea of how to set this up I would
be so grateful!


Chapter 3 #9:
There's an old nursery rhyme that goes like this:
As I was going to St. Ives,
I met a man with seven wives,
Each wife had seven sacks,
Each sack had seven cats,
Each cat had seven kits:
Kits, cats, sacks, and wives,
How many were going to St. Ives?

The last line turns out to be a trick question: only the speaker is
gong to St. Ives; everyone else is presumably heading in the opposite
direction. Suppose however, that you want to find out how many reps of
the assembled multittiude were coming from St. Ives. Write a program
to calculate and display this result. Try to make your program follow
the structure of the problem so that anyone reading your program would
understand what value it is calculating.

You might begin by writing a method that calculates and
returns the total attributable to the man. Since the man
has seven wives with identical totals of their own, the man's
total is seven times a single wife's total:

int man() {
return 7 * wife();
}

(Note that the man himself is not counted, because the rhyme
omits him from the grand total.)

Next, write a method to calculate the subtotal for one wife.
Since she carries seven identical sacks, her total is one (for
herself) plus seven times the subtotal for a single sack:

int wife() {
return 1 + 7 * sack();
}

Continue in this manner until you've solved the problem.
 
R

Roedy Green

I'm new to Java but my instructor doesn't seem to realize it. He
has assigned the following program and I don't even know where to
start. If someone could give me an idea of how to set this up I would
be so grateful!

see http://mindprod.com/jgloss/homework.html
see http://mindprod.com/jgloss/tackling.html

Hint: if you had a method for each category that returned how many
beings in represented. Each the methed for each category would call
the method for some other category and multiply and return the result.
 
L

Lew

Eric said:
(Note that the man himself is not counted, because the rhyme
omits him from the grand total.)

Actually, given the problem statement, the man with the wives needs to be
counted. "I met a man ..." coming from St. Ives.

The man coming from St. Ives should be counted.
 
H

Hal Rosser

Roedy Green said:
see http://mindprod.com/jgloss/homework.html
see http://mindprod.com/jgloss/tackling.html

Hint: if you had a method for each category that returned how many
beings in represented. Each the methed for each category would call
the method for some other category and multiply and return the result.
--

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

No one made it to St Ives
the man was arested for bigamy
That don't rhyme
but it makes more sense
bigity bigity bigity
 
L

Lew

Eric said:
"Kits, cats, sacks, wives, and man"
Was not the question, nor does rhyme nor scan.
Anti-rhymers, meter-manglers, few
Have so misunderstood this verse as Lew.

I see, yet there is that pesky reference to the man with the seven wives who
was also coming from St. Ives. I believe that it is you who misinterpreted -
the line "I met a man" clearly refers to a man coming from St. Ives. The
question refers to who was coming from St. Ives, the poem to who was going to
St. Ives. The latter is not relevant to answer the question.
 
L

Lew

Hal said:
No one made it to St Ives
the man was arested for bigamy
That don't rhyme
but it makes more sense
bigity bigity bigity

It's not bigamy, it's heptagamy.
 
L

Lasse Reichstein Nielsen

I see, yet there is that pesky reference to the man with the seven
wives who was also coming from St. Ives. I believe that it is you who
misinterpreted -
the line "I met a man" clearly refers to a man coming from St. Ives.
The question refers to who was coming from St. Ives, the poem to who
was going to St. Ives. The latter is not relevant to answer the
question.

The question is not whether the man comes from St. Ives, but whether
he should be counted. The question only says "Kits, cats, sacks and
wives//How many were going to St. Ives". If the restriction to kitties,
cats, sacks and wives is retained in the "from St. Ives" question, then
the man is not included. If the question stands on its own, then he
did come from St. Ives.

/L
 

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

Members online

No members online now.

Forum statistics

Threads
474,470
Messages
2,571,809
Members
48,797
Latest member
PeterSimpson
Top