READINGS
(Top)
Problems
(Top)
public static void main(String[] args)
{
int numb = 1;
while (numb <= 32)
{
numb = numb * 2;
System.out.println(numb);
}
}
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);
aProblem.fillArray(10);
aProblem.dumpArray();
}
}
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.
private String pigLatinFor(String word)
Note that this problem appeared on a previous mid-term examination.
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 + ')');
}
EXERCISES
(Top)
|
|
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:
Prepared by David L. March -- Last Revised on September 7, 1998
COPYRIGHT © 1998 BY DAVID L. MARCH