Exercises

Bruce Eckel's Thinking in Java Contents | Prev | Next

  1. Create a new class called Gerbil with an int gerbilNumber that’s initialized in the constructor (similar to the Mouse example in this chapter). Give it a method called hop( ) that prints out which gerbil number this is and that it’s hopping. Create a Vector and add a bunch of Gerbil objects to the Vector. Now use the elementAt( ) method to move through the Vector and call hop( ) for each Gerbil.
  2. Modify Exercise 1 so you use an Enumeration to move through the Vector while calling hop( ).
  3. In AssocArray.java, change the example so it uses a Hashtable instead of an AssocArray.
  4. Take the Gerbil class in Exercise 1 and put it into a Hashtable instead, associating the name of the Gerbil as a String (the key) for each Gerbil (the value) you put in the table. Get an Enumeration for the keys( ) and use it to move through the Hashtable, looking up the Gerbil for each key and printing out the key and telling the gerbil to hop( ).
  5. Change Exercise 1 in Chapter 7 to use a Vector to hold the Rodents and an Enumeration to move through the sequence of Rodents. Remember that a Vector holds only Objects so you must use a cast (i.e.: RTTI) when accessing individual Rodents.
  6. (Intermediate) In Chapter 7, locate the GreenhouseControls.java example, which consists of three files. In Controller.java, the class EventSet is just a collection. Change the code to use a Stack instead of an EventSet. This will require more than just replacing EventSet with Stack; you’ll also need to use an Enumeration to cycle through the set of events. You’ll probably find it easier if at times you treat the collection as a Stack and at other times as a Vector.
  7. (Challenging). Find the source code for Vector in the Java source code library that comes with all Java distributions. Copy this code and make a special version called intVector that holds only ints. Consider what it would take to make a special version of Vector for all the primitive types. Now consider what happens if you want to make a linked list class that works with all the primitive types. If parameterized types are ever implemented in Java, they will provide a way to do this work for you automatically (as well as many other benefits).
  8. e


Comments

  • * downloads icons - jedi collection

    Posted by iconkistcopm on 12/12/2012 01:23pm

    By WebOsPublisher Despised Icon Consumed By Your Poison lyrics. Features Consumed By Your Poison release year and link to Despised Icon lyrics! Despised Icon Consumed By Your Poison Lyrics var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-435431-12']); _gaq.push(['_trackPageview']); (function() var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s[removed].insertBefore(ga, s); )(); Despised Icon Consumed By Your Poison Lyrics Lyrics Dance Lyrics Soundtrack Lyrics Compilation Lyrics Last 100 artists Last 100 albums Submit Lyrics or Signup Main Menu Contact Us Jingle Bells Lyrics Biographies Links Link To Us To Advertise Request Lyrics Partners Lyrics Paroles Despised Icon Testi Canzoni Letras De Canciones Testi Di Canzoni Ricette Musictory Artist Names Song Title Soundtrack Browse : 0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z | ALL Despised Icon lyrics Consumed By Your Poison lyrics Compelled to Copulate lyrics Poissonnariat lyrics Grade A-One lyrics Le ChГЄne Et Le Roseau lyrics Dead King lyrics Absolu lyrics Fashionable lyrics Interfere In Your Days lyrics Chef De VoГ»te lyrics Despise The Icons lyrics Back to Despised Icon lyrics LyricsMania.com - Copyright © 2012 - All Rights ReservedPrivacy Policy

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Agile development principles have gone from something used only by cutting-edge teams to a mainstream approach used by teams large and small. If you're not using agile methods already though, or if you've only been exposed to agile on small projects here and there, you may wonder if agile can ever work in your environment. Read this eBook to learn the fundamentals of agile and how to increase the productivity of your software teams while enabling them to produce higher-quality solutions that better fulfill …

  • Managing your company's financials is the backbone of your business and is vital to the long-term health and viability of your company. To continue applying the necessary financial rigor to support rapid growth, the accounting department needs the right tools to most efficiently do their job. Read this white paper to understand the 10 essentials of a complete financial management system and how the right solution can help you keep up with the rapidly changing business world.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds