Page: (Bot) (Prev) (Next) Class: (Outline) (Summary) (Assign) (Answer) Course: (Cover) (Content) (Glossary)

To: (Readings) (Problems) (Exercises)


  1. Read chapter twelve in the text. This chapter covers the String and StringBuffer classes. These classes are used frequently and some knowledge of their operations is needed to do the problems and exercises.

  2. Look at the application program interface (API) documentation for the following:

  3. Read chapters eight through eleven in the text. This material will be covered next week.

Problems (Top)

  1. Define garbage collection as it is used in conjunction with object-oriented software development.

  2. Explain the difference between overloading a method and overriding a method.

  3. What is the exact output that would be produced by the following main() class method?
      public static void main(String[] args)
        int numb = 1;
        while (numb <= 32)
            numb = numb * 2;

  4. Study the following class:
      public class Problem 

    //Instance variables private int arraySize; private int[] intArray; private int intBase; //Instance constructor

    public Problem(int size) { arraySize = size; intArray = new int[size]; }

    //Instance methods

    public final void fillArray(int base) { intBase = base; for (int index = 0; index < arraySize; index++) intArray[index] = base + index; }

    public final void dumpArray() { int index = 0; System.out.println("ARRAY DUMP"); while (index < arraySize) { System.out.print(" "); System.out.print(index); System.out.print(": "); System.out.println(intArray[index]); index++; } }

    } //class

    What is the exact output that will be produced by the following application that was written to test the Problem class?
      public class ProblemTest
          public static void main(String[] args)
              Problem aProblem = new Problem(5);
    Of course you can always type the source code and run the program. But that would be cheating! Before you do that, try to work out the answer based on your understanding of Java.

  5. Modify the ProblemTest from the previous problem to dump a 25 element array starting with a base of 1.

  6. Code the class declarations for the classes shown in the following class model. You do not need to declare any variables or methods.


  7. To translate an English word into a pig Latin word, move the first letter of the English word to the end of the word and add the letters "ay." For example "java" becomes "avajay" and "programmer" becomes "rogrammerpay." Code the body for the following method that returns the pig Latin equivalent of the specified word:
        private String pigLatinFor(String word)
    Note that this problem appeared on a previous mid-term examination.

  8. The description of the Point class in the line example indicated that the following will compile:
      public String toString()
          return("(" + xPos + "," + yPos + ")");
    The values enclosed in the double quotes are single characters, not strings. But, the following will not compile. Why not?
      public String toString()
          return('(' + xPos + ',' + yPos + ')');


  1. A virtual company named March Educational Software Systems, better known as MESS, has hired you because you claim to be an expert Java programmer. For your first assignment, you are given the following design specification:

    Object Model

    Instances of this class represent the full name of a person.

    Instance Constructors

    construct(first,mid,last: string)
    Constructs a new instance and initializes its state to the specified first, mid, and last name strings. The mid name may be null.

    Instance Operations

    setName(first,mid,last: string)
    Changes the state to the specified first, mid and last name strings. The mid name may be null.

    getFirstName(): string
    Returns a string that contains the first name.

    getMidName(): string
    Returns a string that contains the middle name.

    getLastName(): string
    Returns a string that contains the last name.

    getMailName(): string
    Returns a string that contains the complete name in First Middle Last order.

    getListName(): string
    Returns a string that contains the complete name in Last, First Middle order.

    Utility Operations

    toString(): string
    Returns a string that contains the three parts of the name in the following format:
      Name: last=xxxxxxxxxxx first=xxxxxxxxxx mid=xxxxxxxxx
    Prepared by March Educational Software Systems
    We Do Not Mess Around

    Note that this design is generic because the designer did not assume that Java would necessarily be the implementation language. It is up to the programmer to map the design into the precise syntax of Java while preserving the semantics described in the specification. Your are required to:

    1. Code a Java class that implements this specification of the PersonName class.

    2. Code a Java test program to test your implementation of PersonName.

  2. The PersonName class does not provide an operation that can be used to change only a part of a name. Write a fragment of Java code that shows what you would need to do to change just the last name using the operations that you implemented. You might want to try this fragment in your test program.

Page: (Top) (Prev) (Next) Class: (Outline) (Summary) (Assign) (Answer) Course: (Cover) (Content) (Glossary)

Prepared by David L. March -- Last Revised on September 7, 1998