aspose file tools*
The moose likes Cattle Drive and the fly likes class 2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "class 2" Watch "class 2" New topic
Author

class 2

paul wheaton
Trailboss

Joined: Dec 14, 1998
Posts: 20636
    ∞

At this point you need to have read chapters 1, 4 and 7 in that order. And had the two previous homework assignments completed and returned to you.
Now read chapter 5.
Assignment 3: Write a program that will read in a year and report if it is a leap year. The tricky thing here is that a leap year occurs:

    on every year that is evenly divisible by 4

      except every year that is evenly divisible by 100

        except every year that is evenly divisible by 400.

        In other words, I want to type

          java Leap 2000

          and see

            leap year!



            Assignment 4: Write a program that will read in a number from 0 to 99 and spell out that number. The program must also report any values that are out of range.
            In other words, I want to type

              java Say 22

              and see

                twenty-two

                Extra credit if you can do it with less than 30 strings.
                More extra credit if you can handle numbers as large as nine hundred ninety-nine billion, nine hundred ninety-nine million,
                nine hundred ninety-nine thousand, nine hundred ninety-nine.


                [This message has been edited by Paul Wheaton (edited February 04, 1999).]


permaculture Wood Burning Stoves 2.0 - 4-DVD set
Matt Midcap
Sheriff

Joined: Jan 07, 1999
Posts: 440
Being the student that I am, I have a question about arrays in chapter 5. I have dealt with arrays in C and the book even says that they are alike in syntax alone (p.109 Just Java 1.2). O.k., I can deal with that. Unfortunately the book is gets more confusing as you read along. For example, on p.112 where there is greyed text it says:
"You can never specify the size of an array in a C-style declaration like this:
<PRE>
int sprout [256]; //NO!
</PRE>
The array's size is set when you assign something to it, either in an initializer or a regular assignment statement.
<PRE>
carrot [] = new int[256];
</PRE>
Once an array object has been created with a given size, it cannot change for that array, although you can replace it by assigning a differently-sized array object to it."
Whoaa. Give me a second to stop my eyes from spinning round and round.
I get the first part, int sprout [256], is a no-no.
On the second part, what happened here?
Did carrot[] get assigned as an int array with 256 elements? This is what I think is happening. Could someone explain it to me if I am wrong.
I guess the confusion comes from when they say "The array's size is set when you assign something to it, either in an initializer or a regular assignment statement". To me, nothing has been assigned to "it", and yes the array appears to be initialized, but NOTHING is assigned to it when INITIALIZED either. Am I right?
Thanks for putting up with the newbie questions but its better to learn it here, than get burnt by it out there!


Best Regards,<br />Matt Midcap
paul wheaton
Trailboss

Joined: Dec 14, 1998
Posts: 20636
    ∞

I think you found a typo in the book.
Somewhere in the book the author mentions that if you tell him he'll give you money. Might wanna cruise over to his web site!
I think the carrot line should read:
<pre>
int carrot[] = new int[ 256 ];
</pre>
although I would have used
<pre>
int[] carrot = new int[ 256 ];
</pre>
Does this fix everything?
Basically, all arrays are objects. so "int[]" is like a class called "ArrayOfInt". So you could start with "int[] carrot = null;" and later do "carrot = new int[ 256 ];".
Still lost?
Matt Midcap
Sheriff

Joined: Jan 07, 1999
Posts: 440
Yes, I think I have it now. Thanks!
I'm trying to catch up to class 3, see you there soon!
Matt Midcap
Sheriff

Joined: Jan 07, 1999
Posts: 440
By the way, I did send Mr. Peter Van Der Linden an e-mail.
I humbly asked him if he thought it was a typo and he immediately replied. He said it was a typo and sent me a small list of other typos that are known so far. Most are trivial.
He really seemed like an approachable, cool guy from his e-mail. Truly an excellent personality that all developers should be modeled from.
paul wheaton
Trailboss

Joined: Dec 14, 1998
Posts: 20636
    ∞

If you check out www.split.com/jj you will find my exchnages with him when I tried to do some of the homework from his book.
You are just seeing the beginning of his coolness. Check out his web page and find some really cool stuff.
Maybe you could post that list here somewhere. I'm tempted to create a forum called "Peter van der Linden" - but ....
Matt Midcap
Sheriff

Joined: Jan 07, 1999
Posts: 440
I looked in the book for his homepage address and all I could find was: http://www.afu.com
Is there another?
paul wheaton
Trailboss

Joined: Dec 14, 1998
Posts: 20636
    ∞

I think he has more than one. See http://www.best.com/~pvdl/
 
Don't get me started about those stupid light bulbs.
 
subject: class 2