Object-Oriented Programming in Java - Andrew.cmu.edu

Modify homework 4 exercise 1 the following way: BankServer class: Implement
thread safety for its methods via the synchronized keyword. Introduce an inner
class which extends Thread whose run method should invoke the
applyMonthlyInterest() on all the savings account every 30 seconds. Introduce a
shutdown() ...

Part of the document


Intermediate Java II
MISM/MSIT 95-713
Optional Homework
Due: Sunday, October 23, 7:00pm
This homework is optional. If you do it and get a score higher than any of
your previous homework scores, we will replace the lowest of them with this
one.
There are two exercises in this homework. The first exercise is 20 points.
The second exercise is 100 points. There is additionally a write-up part,
which is 30 points. Although the total makes 150 points, you can obtain
credit only up to 100 points out of this homework.
Although this homework is optional, I recommend each of you doing it. It
will help you develop new programming skills and acquire experience with
new Java APIs. What you will do would include the following:
. Modifying existing programs in response to additional requirements while
retaining the interfaces as much as possible.
. Making design decisions based on loosely defined requirements. Working
with instructor and TA to evolve your design.
. Evaluating your decisions and providing supporting arguments for them.
. Searching the Internet for APIs to implement your design decisions.
. Experimenting with new Java skills like thread, GUI and JDBC programming.
. Packing applications and applets in jar files. Deploying jar files over
Internet.

In this homework, you will be modifying and extending the homework4. You
can have separate eclipse projects for each exercise so that, this way, you
can easily create zip and jar files separately. As before, you may assume
that all the information provided by the user and by the data files would
be valid. Here are the exercises for this homework:
1. Modify homework 4 exercise 1 the following way:
o BankServer class:
. Implement thread safety for its methods via the synchronized
keyword.
. Introduce an inner class which extends Thread whose run
method should invoke the applyMonthlyInterest() on all the
savings account every 30 seconds. Introduce a shutdown()
method to the BankServer class that will stop the thread.
o Atm class:
. Introduce a new transaction type QUIT. This transaction
should send a shutdown() message to the bank server and wait
for 40 seconds for the bank server to shutdown. After that,
halt the program.
. Rather than implementing a single transaction in the console
UI, allow many until the user selects the QUIT transaction.
2. Modify and extend the homework 4 exercise 3 the following way:
o Modify it so that it runs both as an application and as an applet.
Follow the (complete) conversion described in your textbook.
Implement it so that when running as an applet:
. The input file is read from a URL rather than from a local
file.
. Clicking on the Save menu item should display a message
dialog saying that Applet cannot save to a local file.
. Have an Exit menu item in the File menu only if the program
is running as an application.
. In the "Services Ordered" tabbed pane, add two buttons "Add
Service" and "Delete Service". These buttons are activated
only after a customer is selected in the tree. "Add Service"
button runs a wizard to facilitate taking input for billable
and service information so that a new service can be added to
the selected customer. "Delete Service" button removes the
selected billable-service row in the table from the customer.
You should ask a confirmation to the user before deleting a
service.
. In the "Customer Information" tabbed pane, when the user
clicks on the Modify button, introduce a 5 second delay to
simulate the database access delay. Implement thread support
so that the Modify button remains disabled but GUI can still
reply to user events during the delay for modifying the
customer information. After the modification is complete,
Modify button gets re-enabled.
. Think about which of the methods of the model classes should
be made synchronized for thread safety in case multiple views
access them. Make the ones that need to be.
. We have used a sequential text file for getting the input in
our exercises so far. Design a relational database for the
Service Provider application and implement it using JDBC[1].
o Package all executables of this exercise into a jar file, which
would self-execute this application. Put that jar file in a web
server (e.g. Andrew) with an html file to run your program as an
applet.

Overall, implement exception handling especially for all IO and thread
exceptions. In non-GUI code, print out the stack trace on the console if
you catch an exception. In GUI code, additionally display a message via a
modal message dialog. You may assume the input files are all well-formed
and the user always makes the valid actions.

In the write-up part, you should briefly explain the following in a text
file:
. Which interfaces did you want to keep the same in both exercises? Why? If
you change the class name or public APIs, document them.
. Which methods of the model classes in exercise 2 you synchronized for
thread safety? Why?
. Did you use a worker thread or not in exercise 2? Why or why not?
. Explain your design for your wizard GUI. Do you think you achieved good
level of polymorphism and code reuse.
. Document your relational database design in exercise 2.
In your write-up, mention where you located your applet and your html file
(e.g. in which directory in the Andrew server).

Create separate zip files for exercises 1 and 2. Note that your zip files
should contain the documentation files as well. Additionally, create the
jar file for the second exercise. Put all the zip files, the jar file for
the second exercise and your write-up document into a single mega zip file
and submit it before the due time via the Drop Box. You don't need to print
your files as only electronic submission is requested in this homework.

The executable files will be available in Homework5 directory of
http://www.andrew.cmu.edu/user/syucel/95713/homework_solutions/ . No
skeleton code will be provided for this homework.
-----------------------
[1] The maximum point you may get with JDBC database implementation and
documentation is 25 points in this homework, 20 for implementation and 5
for documentation. Likewise, if you don't consider doing the JDBC part, the
rest of the homework constitutes 125 points.