CS1ADS: Algorithms and Data Structures


Coursework 2

Issue date: 2000.01.28

Submission date: 2000.02.11


In order to pass this coursework, you must submit and pass all questions.

Questions that require a program to be written should result in one or more files with a .java extension, all comments should be embedded in the files (with particular emphasis on documentation comments). Questions that require an essay to be written should result in a single file that is one of: a Word file (.doc extension), a FrameMaker file (.fm extension), a LATEX2e file (.ltx extension), an HTML file or a plain ASCII text file (.txt extension).


NB The intention behind the user interface programming exercises is to learn something about how Swing/AWT works.  In a commercial production environment it is unlikely that the user interface would be coded directly, it is more likely that user interface construction tools would be used (cf. Visage, JBuilder, Visual Cafe).  However, such tools can only really be used properly when the programmer has a true understanding of how the package supporting the tool actually works.  Thus, for pedagogical reasons, user interface construction tools should not be used for these exercises.


Question 1

The Java file found by clicking here, is a poor one in that it is not commented.  There are two obvious levels of commenting that could be added depending on the state of Java knowledge of the reader: professional and learner. Take a copy of the file and complete the source code by adding sensible comments so that a learner programmer can quickly and easily understand the code, i.e. comment this as if it were going into a tutorial for new progrqammers to Java.

Not only is the presented code poor, it is also the case that there are some problems with it.  Ascertain what the problems are and make changes to the code to circumvent them.

Question 2

Write a short essay (about 800 words) discussing the conceptsof event and listener. Explain how these concepts contribute to the construction of user interfaces.

Question 3

  1. Extend your copy program from CW1.Q1 (or use the model answer) to include a graphical user interface to collect the filename information from the user if the user types only the command name with no parameters. If the user types any extra information at the command line then the behaviour of the program should be as it was in CW1.Q1.
  2. Extend your tr program from CW1.Q3 (or use the model answer, though remember that this is not totally complete) to include a graphical user interface to collect the option and filename information from the user if the user types only the command name with no parameters. If the user types any extra information at the command line then the behaviour of the program should be as it was in CW1.Q3.

Clearly, this question is not entirely straightforward, indeed it must be categorized as hard at this stage of your learning of Java.  This is no reason not to attempt it, however.  You may need to make extensive use of the tutorials on AWT and Swing as well as the manual pages.  You will most likely put particular emphasis on the following classes:  BorderLayout, FlowLayout, GridLayout, Container, ActionEvent, ActionListener, ButtonGroup, JButton, JDialog, JFrame, JLabel, JList, JMenu, JMenuBar, JMenuItem, JPanel,  JRadioButton, JScrollPane, JTextField -- these are the user interface construction classes from Swing/AWT that I have made use of in my sample answer.

Russel Winder
Last updated: 2000-01-29