To Exam Info

Midterm Review Questions -- Winter 08

 

  1. Convert the decimal numbers 73 and -28 to one byte binary and hex. Use the twos complement representation.

  2. Convert this binary number to hex: Is it positive or negative (twos complement representation)?
    Is it even or odd?

  3. What is the output?

  4. Write a class that contains the following:

    1. A static method isFactor with parameters m and n. It returns true if m divides n.

    2. A static method isPrime with parameter n. It should return true if n has no factors other than 1 and n.

    3. A main method that tests isFactor and isPrime.

    Predict the output of running your main method.

  5. Explain the difference between a parameter and an argument.

  6. What does the term "overloaded" mean?

  7. When should a method be declared public?

  8. When should a method be declared private?

  9. How can you make an instance variable write once?

  10. Write a main method that extracts the fields from this string and stores them into an array

  11. 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)

  12. Here are source code files Pair.java and TestPair.java. Find the errors.

  13. 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.

    1. Draw the UML diagram for the class.

    2. Write the code for the Vehicle class.

    3. Write the code for a TestVehicle class that tests each of the methods of Vehicle.

  14. Write a class that contains the following:

    1. A main method that creates an array of Vehicle objects with some duplicate vins and calls removeDuplicate method, defined in Question 15b.

    2. A method removeDuplicates that removes all objects with duplicate vins in the array. Here is the header:

        public void removeDuplicates(Vehicle[ ] v)
        
  15. Show the variable trace for sorting this array with InsertionSort and with SelectionSort:

  16. Write a program that will accept an arbitrary number of command line arguments, then print out the average word length of these arguments.

  17. 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.

  18. 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.

  19. Modify the Stack class to accept String objects. What is the output from the following?