Exercises

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

  1. Open a text file so that you can read the file one line at a time. Read each line as a String and place that String object into a Vector. Print out all of the lines in the Vector in reverse order.
  2. Modify Exercise 1 so that the name of the file you read is provided as a command-line argument.
  3. Modify Exercise 2 to also open a text file so you can write text into it. Write the lines in the Vector, along with line numbers, out to the file.
  4. Modify Exercise 2 to force all the lines in the Vector to upper case and send the results to System.out.
  5. Modify Exercise 2 to take additional arguments of words to find in the file. Print out any lines in which the words match.
  6. In Blips.java, copy the file and rename it to BlipCheck.java and rename the class Blip2 to BlipCheck (making it public in the process). Remove the //! marks in the file and execute the program including the offending lines. Next, comment out the default constructor for BlipCheck. Run it and explain why it works.
  7. In Blip3.java, comment out the two lines after the phrases “You must do this:” and run the program. Explain the result and why it differs from when the two lines are in the program.
  8. Convert the SortedWordCount.java program to use the Java 1.
  1. Repair the program CADState.java as described in the text.
  2. (Intermediate) In Chapter 7, locate the GreenhouseControls.java example, which consists of three files. In GreenhouseControls.java, the Restart( ) inner class has a hard-coded set of events. Change the program so that it reads the events and their relative times from a text file. (Challenging: Use a factory method from Chapter 16 to build the events.)


Comments

  • There are no comments yet. Be the first to comment!

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

Top White Papers and Webcasts

  • Live Event Date: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

  • With the average hard drive now averaging one terabyte in size, the fallout from the explosion of user-created data has become an overwhelming volume of potential evidence that law-enforcement and corporate investigators spend countless hours examining. Join Us and SANS' Rob Lee for our 45-minute webinar, A Triage and Collection Strategy for Time-Sensitive Investigations, will demonstrate how to: Identify the folders and files that often contain key insights Reduce the time spent sifting through content by …

Most Popular Programming Stories

More for Developers

RSS Feeds