This first assignment is intended more as a warm-up exercise, to bring you back up to speed on Java from last semester (or perhaps even earlier, for some of you). If you find it especially difficult, see me: it may be that you are mis-interpreting my intent, or that I can help out in some other way.
Note: this is not (yet) a GUI (graphical user interface) assignment! Students from last semester's CS 141 class have not seen GUI code yet. We may enhance the assignment at some point to include graphics, but most GUI systems using actial windows (or panels, etc.) would make this assignment trivial by doing the work for you.
The assignment is a little (textual) simulation of a windowing system: you should imagine some over-lapping rectangles on the screen, representing windows in a modern GUI, on any of which a user might click. When a window (i.e., a rectangle) is clicked on, it would be brought to the front (and all windows re-drawn). In order to simulate the window ordering, we will just write out the names of the windows in order, from top to bottom ... but in a picture form, they might look like one of these (depending on the GUI used):
To get the original window data, you should read the lines of a text file: each line will contain four positive integers representing the upper-left corner (x and y coordinates) and the width and height. These will be followed on the same line by a name (text string) for the window (you might want to trim the string to eliminate stray spaces from the beginning and end).
Your program should proceed as follows:
Of course, some windows might remain completely obscured, and thus not selectable, or even visible. Oh well.
ArrayListfor the latter).
toStringmethod for the window-list printing, in order to make your job easier.
Scannerto read the data and the
trim()method to trim your window name strings.
I will release some sample input data files in the next few days, but you should develop your own for testing.
PS: when and if we do modify the program to use some real graphics, you would want it to be as easy as possible to "upgrade" your code to work in that new environment. The use of objects, classes and other standard Java techniques should help here, but you should think consciously about this issue as you design your program (and in general when you design any program). Building programs that are robust in the face of such changes is a difficult skill to learn, but one that you should definitely begin to cultivate now.