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

  • Learn How A Global Entertainment Company Saw a 448% ROI Every business today uses software to manage systems, deliver products, and empower employees to do their jobs. But software inevitably breaks, and when it does, businesses lose money -- in the form of dissatisfied customers, missed SLAs or lost productivity. PagerDuty, an operations performance platform, solves this problem by helping operations engineers and developers more effectively manage and resolve incidents across a company's global operations. …

  • Live Event Date: December 18, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT The Internet of Things (IoT) incorporates physical devices into business processes using predictive analytics. While it relies heavily on existing Internet technologies, it differs by including physical devices, specialized protocols, physical analytics, and a unique partner network. To capture the real business value of IoT, the industry must move beyond customized projects to general patterns and platforms. Check out this upcoming webcast …

Most Popular Programming Stories

More for Developers

RSS Feeds