CSC 222: Computer Programming II
Spring 2005

HW2: Java GUI


Part 1: Guessing Game

For the first part of this assignment, you will write a graphical user interface that will work with the GuessRange class from HW1 to play the guessing game. The interface should prompt the user for his/her guess, displaying the range to choose from. The user should be able to enter a guess in a text field and click a button to submit the guess. As before, the number of guesses should be displayed (in the same label as the prompt) when the correct guess is finally made.

For this version, you may assume that the initial range is 1 to 100. The following is one possible look that the interface might take:

Once you have this interface working, make the following modifications.

Part 2: Talk Like a Pirate

The Translator class has been provided for you, which can be used to translate words and phrases from one language to another. When constructed, a Translator object reads in vocabulary from a file, consisting of pairs of words or phrases. For example, in an English to Spanish translator, the pair "bathroom|bano" might be read in. Once these word/phrase pairs have been read in and stored, the translate method can be called on a string, and any word from the vocabulary that is found will be replaced by the corresponding word. For example, if the English-to-Spanish translator were used, the a call to translate would replace every occurrence of "bathroom" with "bano" in the parameter.

A vocabulary file, pirate.txt has been provided for you that contains English-to-Pirate translations. You are create a graphical user interface that will work with the Translator class to provide an easy-to-use English-to-Pirate translator. The GUI should have a label at the top of the frame, a text area in which the user can enter text, and a button that initiates the translation. When the button is clicked, the text in the text area should be translated and the resulting text should be displayed back in the text area.

For example, the first screenshot shows the GUI with the Gettysburg address entered in the text area. The second screenshot shows the GUI after clicking the button and performing the translation.

Once you have this interface working, make the following modifications.