Homework #3

You must submit your work to your instructor before midnight on due date. Failure to do so will result in late penalties, see the syllabus for grading detail.

Problem 1 (10 points)

Integer is part of the Java API. Suppose you attempt to extend the Integer class and add a new method that returns the integer as a String that is written in hexadecimal, etc. Explain why you're having trouble doing it.

Problem 2 (20 points)

Random is part of the Java API. It has various methods to generate random integers, random doubles, etc. However, Random does not have a method that will generate a random integer between two specified integers (like 3 and 11). That would be very useful in many applications. Your task is to create a class called ImprovedRandom that can do everything that Random can do, but also adds this handy method. Use inheritance to extend Random.

Note: Your class is supposed to do everything that Random can do, so pay careful attention to what constructors should be possible. For example if Random can be instantiated with a seed parameter, then yours should be able to do the same.

The other thing you have to do for this problem is to write a tester for your new class. This is not a unit-test (you have to write unit-tests anyway), instead a wrapper program that uses your class and validates that the sequence of numbers it generates appears to be random.

Problem 3 (20 points)

StringTokenizer is part of the Java API. This class takes a string filled with words and, each time the method nextToken() is called, it returns the next word in the string. Create a new class named ImprovedStringTokenizer that acts just like a StringTokenizer but has a new method that returns all of the words in a single array.

For example, if the string is "This class is easy", then your new method will return an array where the 0th element is "This", the 1st element is "class", the 2nd element is "is", and the 3rd element is "rocks".

Problem 4 (40 points)

In this problem you'll get to write a little bit of JavaScript. For simplicity, take the problem described in HW-1 and produce a JS implementation.


  • There is no main() in JS, code gets interpreted line by line
  • The requirement for unit-testing is waived for this problem; this is to spare you the need to learn a new unit-testing framework

Important: Don't forget to re-read the syllabus to make sure you understand all the deliverables for assignments in this class, including this one.


Problems #1, #2, and #3 were inspired by an assignment posted here.

Last update: Mar 30, 2009 Virgil Bistriceanu cs445 Computer Science

$Id: hw3.html,v 1.1 2009/03/30 19:47:45 virgil Exp $