CSC 160
Lab Exercise 1
18 September 2008
5 Points
due before the next class
In this exercise you will extend an existing program in which the user selects a file from a list and
the system displays some information about it.
- The source file is SelectedFileType.java, located in the Lab 1 folder. This is itself
found on the "I" network drive folder for this course (I:\CSC\160\20084-CSC-160-1E\Common).
Copy it into your workspace.
- Study the source code and run it a few times to see what it does.
- The getExtension() method is supposed to return the file extension of the file name given
to it. It is pretty stupid right now. It returns ".html" regardless of the actual file
extension. Modify it to work correctly. Note that if the file does not have an extension, it returns
null.
- The class contains a data structure called a Hash Map that associates a file extension with a short description.
Currently it knows .doc and .html. You add new associations using the put()
method, as shown. You can retrieve a description, given an extension, using the get() method,
as shown (it returns null if the extension does not have an associated description).
- Currently, the program displays the file path name and extension description in two different
message dialogs. Combine these into one message dialog with those two pieces of information on two
lines.
- In the message dialog you just modified, display the file name instead of path. You are to extract
the file name from the path using String methods. The path may be something like
Z:\Joe\CSC100\resume.doc, and you should display only the resume.doc part.
- For 2 bonus points, extend the program to do the following: If the file
extension does not have an associated description, ask the user to enter one.
Then put the extension and description into the Hash Map so they can be used
later.
- When finished, send me your SelectedFileType.java file as an email attachment to
psanderson@otterbein.edu.