CS 257
User Interface Design
Paired Values and File Formats
David B. Levine
Computer Science Department
St. Bonaventure University
Copyright, 2002, 2004,
2006
Objective
By the conclusion of this lab period, you will have:
- Learned a new use for maps.
- Gained experience with program customization.
- Extended the Sudoku project a bit.
Sliding Around
- You are to write a new class, NameValuePair, that contains (name,value)
pairs. Your class should take a File object as a parameter to the
constructor and it should read the data from that file. Each line in
the file may be assumed to be a (name,value) pair. The first word,
i.e. everything up to the first space, is assumed to be the name; everything
after that - ignoring leading white space - is assumed to be the value.
You are to store these two strings in some form of a Map so that you may
respond to "get" queries. A "get" query (called
"lookup" in lecture yesterday) takes a String and returns the
value associated with the given name. If the String is not a known
name, one of three things may happen: 1) null
may be returned, 2) the empty string may be returned, or 3) the name may be
returned. Your class should have three constants:
NameValuePair.MISSING_NULL,
NameValuePair.MISSING_EMPTY, and
NameValuePair.MISSING_NAME. You should
include a method, setMissingBehavior, that
takes one of these constants as a parameter and causes the class to behave
accordingly.
-
Now use your class to build the "hello, person" program described in class
yesterday. (This is the one that asks the user for a name and then
greets that person by name.) Use two different data files - one in
English and one in some other language - to demonstrate your program.
Print copies of your program, your data files, and your output.
- Next change the data file format for your Sudoku program. This means
that you will have to change your data files. Your new data file format
should be (name, value) pairs. You should have values for the rows,
columns, board, and original board. Since these are line-based values, you
will need to change the idea of "state" in the existing program to remove the
embedded newline characters. You may also need to modify the model, as
discussed in class, so that it has appropriate getters. Finally, you will
need to change details of both your Open and Save methods...
To Hand In:
-
Turn in the printouts from Step 2, and a listing of the
Sudoku program with the "changed" code highlighted, along with a cover page.
Due Date
This lab is due
Monday, April 20, by 4 p.m.
Assignment Type (see Academic Practices and Policies Document):
Group Project With Limited Collaboration