Chapter 6: Intro to OOP

The exercises here are taken from my forthcoming book The Java Developer's Resource.

Quiz

  1. What's the difference between an object and a class?
  2. What's the difference between an instance of a class and an object in that class?
  3. What's the difference between a local variable and a member variable?
  4. What's the diffidence between a static field and a non-static field?

Exercises

  1. Convert the command line programs of exercises 1, 5, 7, 8, 9, 10, 11, and 12 from chapter 4 into methods that do the calculations but don't handle any input. Then write a main method to handle the input and call the new methods. Do you notice anything similar about the new main methods?
  2. Java lacks a complex data type. Write a Complex class that represents a single complex number and includes methods for all the usual operations, i.e. addition, subtraction, multiplication, division, etc.
  3. Hard: Create a VeryLong class that will store an integer of arbitrary length. The methods of this class should be similar to those of the Complex class.
  4. Using the VeryLong class of the last problem, create a Rational class that handles arbitrarily precise fractions.
  5. Hard: Modify the toString() method of the Rational class so that it outputs results as mixed numbers in reduced form (i.e. 1 + 3/8 instead of 1 + 6/16 or 11/8). Hint: The greatest common denominator of two numbers u and v is the same as the greatest common denominator of u and u - v.


[ Exercises | Cafe Au Lait | Books | Trade Shows | Links | FAQ | Tutorial | User Groups ]

Copyright 1996 Elliotte Rusty Harold
elharo@sunsite.unc.edu
Last Modified August 20, 1996