- Convert the decimal numbers 73 and -28 to one byte binary and
hex. Use the twos complement representation.
- Convert this binary number to hex:
00110110111100010110011110110110
Is it positive or negative (twos complement representation)?
Is it even or odd?
- What is the output?
int x = 0x4D, y = 0xEA;
System.out.printf("%X %d", x | y, x & y);
- Write a class that contains the following:
- A static method isFactor with parameters m and n. It
returns true if m divides n.
- A static method isPrime with parameter n. It should return
true if n has no factors other than 1 and n.
- A main method that tests isFactor and isPrime.
Predict the output of running your main method.
- Explain the difference between a parameter and an argument.
- What does the term "overloaded" mean?
- When should a method be declared public?
- When should a method be declared private?
- How can you make an instance variable write once?
- Write a main method that extracts the fields from this string
and stores them into an array
"abc;145;true;M;99.95;end"
- Given this UML diagram,
which of the following method calls is legal from within the
main?
f( ) |
Main.f( ) |
main.f( ) |
this.f( ) |
f('a') |
Main.f('a') |
main.f('a') |
this.f('a') |
f(5) |
Main.f(5) |
main.f(5) |
this.f(5) |
x = f( ) |
x = Main.f( ) |
x = main.f( ) |
x = this.f( ) |
x = f('a') |
x = Main.f('a') |
x = main.f('a'); |
x = this.f('a'); |
x = f(5) |
x = Main.f(5) |
x = main.f(5) |
x = this.f(5) |
g( ) |
Main.g( ) |
main.g( ) |
this.g( ) |
g('a') |
Main.g('a') |
main.g('a') |
this.g('a') |
g(5) |
Main.g(5) |
main.g(5) |
this.g(5) |
x = g( ) |
x = Main.g( ) |
x = main.g( ) |
x = this.g( ) |
x = g('a') |
x = Main.g('a') |
x = main.g('a') |
x = this.g('a') |
x = g(5) |
x = Main.g(5) |
x = main.g(5) |
x = this.g(5) |
- Here are source code files
Pair.java and
TestPair.java. Find the errors.
- Design and test a Vehicle class. Use the instance variables
makeModel, vin, year and miles. Include getters for each variable
and a setter for year with the constraint that miles cannot be rolled back.
Also include toString and equals methods. Two Vehicle objects are equal
if their vins are equal. Include a parameterized constructor for
creating a Vehicle object.
- Draw the UML diagram for the class.
- Write the code for the Vehicle class.
- Write the code for a TestVehicle class that tests each
of the methods of Vehicle.
- Write a class that contains the following:
- A main method that creates an array of Vehicle objects with
some duplicate vins and calls removeDuplicate method, defined in
Question 15b.
- A method removeDuplicates that removes all objects with duplicate
vins in the array. Here is the header:
public void removeDuplicates(Vehicle[ ] v)
- Show the variable trace for sorting this array with InsertionSort
and with SelectionSort:
{ 43, 11, 25, 33 }
- Write a program that will accept an arbitrary number of
command line arguments, then print out the average word length
of these arguments.
- Write a program that will accept a filename as a
command line argument, then print out the average word length
of the words in that file.
Use raven.txt to test
your program.
- Write a program that will input input and output filenames as
command line arguments. The program should read the file, then
output the same content to the output file with the exception that
all words of length 4 are replaced with ****.
Use raven.txt to test
your program.
- Modify the Stack class
to accept String objects. What is the output from the following?
Stack s = new Stack( );
s.push("dog");
s.push("cat");
s.push("horse");
s.push("squirrel");
s.pop( );
System.out.println(s.getTop( ));
s.push("guinea pig");
s.push("ferret");
s.pop( );
s.pop( );
s.pop( );
s.push("mouse");
s.pop( );
s.pop( );
System.out.println(s.getTop( ));