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

  • The explosion in mobile devices and applications has generated a great deal of interest in APIs. Today's businesses are under increased pressure to make it easy to build apps, supply tools to help developers work more quickly, and deploy operational analytics so they can track users, developers, application performance, and more. Apigee Edge provides comprehensive API delivery tools and both operational and business-level analytics in an integrated platform. It is available as on-premise software or through …

  • Live Event Date: September 10, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Modern mobile applications connect systems-of-engagement (mobile apps) with systems-of-record (traditional IT) to deliver new and innovative business value. But the lifecycle for development of mobile apps is also new and different. Emerging trends in mobile development call for faster delivery of incremental features, coupled with feedback from the users of the app "in the wild". This loop of continuous delivery and continuous feedback is …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds