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

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

  • On-demand Event Event Date: October 23, 2014 Despite the current "virtualize everything" mentality, there are advantages to utilizing physical hardware for certain tasks. This is especially true for backups. In many cases, it is clearly in an organization's best interest to make use of physical, purpose-built backup appliances rather than relying on virtual backup software (VBA - Virtual Backup Appliances). Join us for this webcast to learn why physical appliances are preferable to virtual backup appliances, …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds