Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Create a project (named Proj4bSmith if Smith is your last name) that consists of these files:

TransactionChecker.java TransactionLogger.java TestTransactionChecker.java Transaction.java (from Project 4).

Also download the transactions.txt file. Place it in the project folder. Modify the TransactionChecker class:

Make this class a derived class that extends the base class Observable.

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.

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 Transactionobject. To do this, use the Observable methods setChanged and notifyObservers.

Modify the TransactionLogger class:

Have it implement the Observable interface, which means that an update method is required.

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. Write a TestTransactionChecker class. In a main method:

Declare and instantiate a new TransactionChecker object.

Declare and instantiate a new TransactionLogger object.

Add the TransactionLogger object as an observer to the TransactionChecker object.

Call the checkTransactions method of the TransactionChecker object.

Transaction class from project 4:

public class Transaction {

private int _id;

private String _buyer;

private String _seller;

private double _amount;

private String _timestamp;

public Transaction() {};

public Transaction(int _id, String _buyer, String _seller, double _amount, String _timestamp) {

this._id = _id;

this._buyer = _buyer;

this._seller = _seller;

this._amount = _amount;

this._timestamp = _timestamp;

}

public int getId() {

return _id;

}

public String getBuyer() {

return _buyer;

}

public String getSeller() {

return _seller;

}

public double getPrice() {

return _amount;

}

public String toString() {

return "_id: " + _id + " _buyer:" + _buyer + " _seller: " + _seller;

}

}

 // Source Code Cile: TransactionChecker.java // For Project 5S. // To be modified. import java.io.File; import java.io.FileNotFoundException; import java.util.Observable; import java.util.Scanner; public class TransactionChecker { Scanner _in; public TransactionChecker(String fileName) throws FileNotFoundException { _in = new Scanner(new File(fileName)); } public void checkTransactions( ) { while(_in.hasNextLine( )) { String line = _in.nextLine( ); String[ ] fields = line.split(","); System.out.printf("%s %s %.2f %s ", fields[0], fields[1], Double.parseDouble(fields[2]), fields[3]); } _in.close( ); } } 

// Source code file TransactionLogger.java // For Project 5. // To be modified. import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.Observable; import java.util.Observer; public class TransactionLogger { PrintWriter _log; public TransactionLogger(String fileName) throws FileNotFoundException { _log = new PrintWriter(fileName); } } 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

List the nine major components in a database system environment.

Answered: 1 week ago