|
Computer Science 136 Data Structures and Advanced Programming Williams College Fall 2005
|
|
Lab 10: How many millimeters in a furlong?
Due: Monday, December 5, 2005 at 9:00 AM
Short Answers
Complete the following problems from the book and turn them in as a
text file lab10.txt at the start of lab.
Lab Program
Do the laboratory in Section 15.6 in the book.
- Start by trying out the units program. You can run it at
the Unix command prompt.
- Design your Java program. Design your class with public methods
that would allow reuse. Your main method should construct an
instance of the class, and call public methods as driven by the
interactive interface. You need not submit a design document, but I
recommend writing one before you dive into the code.
- Your program should take either zero or one command-line
arguments. When run with no arguments, it should read its database
from a file units in the current directory. If there is an
argument, it should read from the file specified by that argument. A
sample input file is in the shared directory under labs/units.
- Work with a small example during the development process.
Remember to develop and test incrementally.
- We have used Scanners to collect keyboard input
throughout the semester. This same class can be used to read from a
file. To create a Scanner that reads its input from a file
test-input:
Scanner input = null;
try {
input = new Scanner(new File("test-input"));
} catch (FileNotFoundException e) { Assert.fail("File not found."); }
Note that an exception is thrown if the file is not found. You will
also need to import java.io.*; to make this work.
- You will still need a "regular" Scanner to process
responses from the keyboard.
Try to emulate the behavior of units as closely as you can.
What to Turn In
Turn in a tar file lab10.tar containing your source file Units.java and a file README.lab10 with the answers to the
following thought questions.
- 1 and 2.
- Do the thought questions at the end of the lab.
- 3.
- The units program reads its database of units from a
file. Where is that file? (Hint: man units) It includes
prefixes like kilo- and milli-. (Have you ordered a
zettabyte hard disk yet?) How might you include support for these
prefixes in your implementation?
- 4.
- Did you choose a list representation or an adjacency matrix
representation for your graph? What are the relative advantages and
disadvantages for a graph such as the one you constructed?