The midterm will be held live during our regularly scheduled in-person class. The exam will appear as an assignment on canvas a few minutes before our regular class time. Solutions-- which will mostly take the form of Java files-- must be uploaded to Canvas no later than five minutes after the end of our regular class time. You will have access to the Internet, but communicating with anyone or anything about the exam (except me) is not allowed. In particular, I don't want any group efforts and I don't want any plagiarism.
I'm planning two problems, similar to homework problems, although a bit simpler.
· In IntelliJ you should have a project called mvcApps that contains these packages: mvc, stopLight, and minefield. All of these programs should run, and you should understand how the code works.
· Create a new package called midterm. It's likely that the questions on the midterm will be similar to bits and pieces of these other programs, so it should be possible to borrow bits and pieces of code from these other programs and adapt them to the midterm.
· If you can’t use mvc either because it doesn’t work or you don’t know how, implement the application from scratch, but using the Model-View-Controller pattern (for partial credit).
· Become adept at using the code generators under the Code menu in IntelliJ. In an exam situation where time is precious, it's good to be able to quickly generate constructors, getters, setters, delegators, and overrides. I won't be fussy about coding standards such as making member variables private, etc.
· Learn how to export your packages to the file system, zip the source code files into a single .zip file (unless you are only submitting a single file), and upload this to canvas. You should include solutions to all problems in a single zip file. This includes your mvc package. If you don't provide this package I won't be able to run your code!
· Have a "cheat sheet" with links to the important web pages covered in lecture.
We learned to use StarUML to create UML use case and class diagrams. The use case model consists of one or more use case diagrams that show the application's major functions and the actors they interact with. Class diagrams are used to create domain and design models. Combined, the use case diagrams and the domain model provide a model of a proposed application from the user's perspective. The design model provides a model of the system from the developer's perspective.
· Be able to translate a textual description of a domain into a domain model.
· Be able to translate between class diagrams and Java.
· Look for places to incorporate the patterns we discussed.
· Know what the UML arrows mean and how to use them.
Design patterns are reusable design fragments. Be able to use them in class diagrams and be able to implement them in Java.
· Actor-Role
· Types as Objects
· Strategy
· Composite
· Adapter
· Publisher-Subscriber
· Commands as Objects
· Abstract Factory
· Model-View-Controller
Know the basic concepts behind Java's awt and swing packages. In particular:
· Listening for action events fired by controls (Publisher-Subscriber pattern)
· Laying out a JPanel using nested panels and layout managers (Composite & Strategy patterns)
· Overriding paintComponent for custom graphics.
All of these ideas come together in the design of the mvc framework. Be sure you have an intimate understanding of how the framework works and how to customize it. Be sure your copy of the framework works properly.
Note: Starred problems are probably too long or weird or difficult for the midterm but still offer good practice.
A processor executes the instructions in its program. Each instruction updates the processor's accumulator when executed. For example, an add instruction increments the processor's accumulator by an amount specified by the add instruction's argument (arg). Here's a class diagram:
Implement this diagram in Java. Implement the methods as best you can.
Here's a test driver: TestProcessor.java.
Here's my solution: Processor.java.
The control panel of a nuclear reactor gives the operator two options: increment the temperature by a random amount less than 100 degrees, and decrement the temperature by a random amount less than 100 degrees. A thermometer in the view panel displays the reactor's temperature. If the reactor's temperature goes above 5000 degrees a dialog box pops up warning that the reactor is too hot.
Implement Reactor Control as an mvc app.
Add a new item under the Help menu called History. When selected it pops up a dialog box containing the names of all commands successfully executed during the current session in order of their execution.
Solution:
1. Add the following field to AppPanel:
List<String> history = new ArrayList<String>();
2. Add the following line to the end of actionPerformed try-block:
history.add(cmmd);
3. Add "History" the the Help menu in createMenuBar.
4. Add the following clause to actionPerformed:
else if (cmmd.equals("History")) {
Utilities.inform(history.toArray(new
String[history.size()]);
}
A stack calculator uses a stack to store inputs and intermediate values. Implement a stack calculator as an mvc customization. Here’s a screen shot:
The content of the stack is shown in the view panel. The Help menu item explains how it works:
For example, if the user clicks the Add button, 20 and 5 are replaced by their sum:
Here’s my solution: StackCalculator.java.
Notes:
1. Admittedly, this is probably too much code for a midterm. There are five buttons and the view involves a JList control. Although we used JLists in the Mini Mac assignment, they may be too exotic for a midterm.
2. That said, there are lots of shortcuts you can take. I didn’t do any error checking. I didn’t create getters and setters for fields. I auto-generated constructors and the implementation of StackFactory. All of the command classes could go in a single file. Implement one, then copy/tweak it four times for the others. I didn’t bother using layouts for my panels, I just went with the default flow layout. I wrote the code for adding a single button to the control panel, then copy/tweaked it four times. I don’t care about Help, About, or Title, make something up. In fact, you could assume there will be an mvc application that will go into a package called midterm. See how much of it you can write before the midterm.
3. Don't forget to include your mvc package with your submission.
Translate the following diagram into Java. Your solution should be contained in a single file called PipeLine.java.
Similar to Spotify and ITunes, Rave
is an application that allows users to curate their own streaming media
library.
A library has a list of playables. A
playable is any object that implements the Playable interface:
interface Playable {
public void play();
}
Playables currently include audio
recordings, video recordings, and playlists (i.e. lists
of playables).
The playlist's play method uses an
ordering algorithm to determine which playable should be played next. An
ordering algorithm has a next method that returns the next Playable that should
be played and a hasNext method that returns false when all of the playables in
the play list have been played. There are several algorithms the user can
dynamically switch between: sequential, random, and looping. More may be added
in future versions.
VideoRecording is a legacy class from
an earlier version. Management demands that it must be reused here. Alas, it
does not implement the Playable interface. In fact, instead of a play method,
it has a stream method that does the same thing.
* Draw a class diagram showing how you
would design Rave libraries. Use any relevant design patterns. Don't worry
about presentation stuff (views and controllers). We are only interested in
modeling what is described above and solving the accompanying design problems.
Implement the diagram.
Here are a few
design patterns and their participants:
Pattern: Composite
Participants: Component, Composite, Primitive
Pattern: Strategy
Participants: Context, Strategy, Concrete Strategy
Pattern: Adapter
Participants: Client, Target, Adapter, Adaptee
Pattern: Publisher-Subscriber
Participants: Publisher, Concrete Publisher, Subscriber, Concrete Subscriber
Pattern: Predator-Prey
Participants: Wolf, Sheep, Shepard
Say which of the above design patterns would be most
appropriate to use in each of the following situations; show which classes
would correspond to which participants. If there is no class explicitly
mentioned for a particular participant, then you may invent one, but it should
make sense in the context of the situation.
1. An investors want to be alerted when a stock hits a certain price.
2.
An analog TV uses a converter to receive signals from a
digital source.
3. A seller needs to modify the way it negotiates with different types of buyers. For example, with some buyers the seller may accept the first offer, for others the seller may split the difference, and for others the seller may hold firm to the original price.
4. A robot executes a list of instructions. Instructions include move, turn, and sub-routines. A sub-routine is a list of instructions.
A class has a name, a visibility, fields,
methods, and may extend one other class. A field has a name, a visibility, and
a type (type = class). A method has a name, a visibility, a return type, and
parameters. A parameter has a name and a type. There are four possible
visibilities: PRIVATE, PROTECTED, PACKAGE, and PUBLIC.
*Translate the above description into a
UML class diagram.
Now translate your diagram into code!