To Documents

IT 313 -- Project 7

Observer Software Pattern -- Transaction Observer. 75 points.

Goal: Use the classes Transaction, TransactionChecker (Observable), TransactionLogger (Observer),as specified in Details 2 and 3. Write a TransactionChecker class as specified in Detail 4.

Deliverables: Zip file of: the IntelliJ project with two modules: (1) deliverables, which contains the classes Transaction.java, TransactionChecker.java, TransactionLogger.java, and TestTransactionChecker.java (don't forget the source code comments), (2) observer, which contains the package it313.util; this package contains the Observable.java and Observer.java files from the Observer Example.

Important: use the Observable class and Observer interface from the Observer Example. Do not use the Observable.java and Observer.java files from the Java Class Library because these files are depreciated. 30 point deduction if you use the files from the Java Class Library.

Also, remember: don't compare strings for equality like this:
      s == t
Compare for string equality like this:
      s.equals(t)

Details

  1. Create a project (named Proj5Smith if Smith is your last name) that consists of these files:
    Also download the transactions.txt file. Place it in the project folder.
  2. Download the Observable.java and Observer.java files from the Observer Example into the package it313.util. Do not use the observer files from the Java class library, which are depreciated. 30 point deduction if you use them.
  3. Modify the TransactionChecker class:
    1. Make this class a derived class that extends the base class Observable.
    2. In the while loop, replace the printf statement with code that creates a Transaction object. For the transaction id, use an autogenerated id that starts with 1001 and increases by 1 for each new Transaction object created.
    3. After the Transaction object is created in the while loop, write an if statement that notifies the observers if a transaction is found where amount is greater than $50,000 and the buyer is Eugene Eko. Notify all observers by sending them the Transaction object. To do this, use the Observable methods setChanged and notifyObservers.
  4. Modify the TransactionLogger class:
    1. Have it implement the Observer interface, which means that an update method is required.
    2. Add an update method with this header:
      public void update(Observable obs, Object info)
      
      Write the info object (which is actually a Transaction object) out to the log file. After that, flush the output buffer, which forces the info be written to disk. Don't forget the @Override statement, which indicates that you are either overriding a method from a base class or implementing a required method from an interface.
  5. Write a TestTransactionChecker class. In a main method:
    1. Declare and instantiate a new TransactionChecker object.
    2. Declare and instantiate a new TransactionLogger object.
    3. Add the TransactionLogger object as an observer to the TransactionChecker object.
    4. Call the checkTransactions method of the TransactionChecker object.
    5. Close the TransactionLogger object.

Grading Breakdown: TransactionChecker: 25%; TransactionLogger: 25%; TestTransactionChecker: 25%; Comments: 15%; Indentation: 5%; Properly Submitted: 5%.