Question: Implement and test a TransactionManager class that manages objects that implement the PurchaseReceiptinterface in Java . These objects are Transaction objects and the objects of
- Implement and test a TransactionManager class that manages objects that implement the PurchaseReceiptinterface in Java. These objects are Transaction objects and the objects of their derived classes.
-
This is PurchaseReceipt.java or the Purchase Receipt interface package it313.proj4; public interface PurchaseReceipt extends Comparable
{ public int getId( ); public String getBuyer( ); public String getSeller( ); public double getAmount( ); }
- Deliverables: Cover document explaining what you implemented in your project, csource code files: Transaction.java, GoldTransaction.java, LumberTransaction.java, TransactionManager.java, Test3.java, generated Javadoc documentation.
- Details:
- Use this TransactionManager UML Diagram to help you implement the TransactionManager class..
- The TransactionManager contains one instance variable defined like this:
private ArrayList
This collection is instantiated in the TransactionManager constructor like this:_col; _col = new ArrayList
( ); - The specs of the TransactionManager methods:
Method Information Parameter add Append a PurchaseReceipt object to _col PurchaseReceipt object clear Clear out _col by removing all its objects. None getCount Return number of objects in _col None getAll Return array list of all objects sorted by _id None findBuyer Return array list of all objects from _col with specified buyer, sorted by _id. Name of buyer (String) findSeller Return array list of all objects from _col with specified seller, sorted by _id. Name of buyer (String) findId Return object with specified _id. Id to find (int) save Serialize transaction manager to file None load Deserialize transaction manager from file None - The Transaction and TransactionManager classes implement the Serializable interface so that it can be serialized to or deserialized from a .ser file.
- Write a traditional test class Test3 that tests your TransactionManager class.
- Optional: test your classes on using the CommandShell class.Change the name of the class file to CommandShell.java if necessary.
- Include Javadoc comments in each of your classes. When your project is finished, run the javadoc utility and copy the generated html files to a separate folder named javadoc in your project zipfile. Use Javadoc comments at the beginning of classes, constructors, and methods. Format of Javadoc comment before a class:
/** * Short description of class * * @author Stan Smith * @version 1.6 9/26/17 */ public class MyClass { // class body }Format of a Javadoc comment before a constructor or method:/** * Short one line description. *
Format of a Javadoc comment before a public field:* Longer description. If there were any, * it would be here. *
* And even more explanations to follow in * consecutive paragraphs separated by HTML * paragraph breaks. *
* @param parameter description. * @return return value description * @throws description of exceptions thrown */ public int methodName(...) { // method body }
/** * Description of variable here. */ public final int constantName = 1234;
Grading Breakdown: TransactionManager Functionality: 50, Test3: 25, Javadoc Comments and Eclipse generated documentation: 15, Indentation: 5, Submitted: 5. Deduction for not submitting cover document: -10. Extra Credit: up to 10 points extra credit for implementing the Command Shell.
This is the code for the Transaction class, GoldTransaction class, and the LumberTransaction class //The Transaction class implements the PurchaseReceipt interface, which inherits from the // Comparable interface. Test the compareTo method in the Transaction class to make sure that // its objects are compared correctly. public class Transaction implements PurchaseReceipt { private int _id; private String _buyer; private String _seller; private double _amount; private String _memo; private String _timestamp; public Transaction(int _id, String _buyer, String _seller, double _amount, String _memo, String _timestamp) { this._id = _id; this._buyer = _buyer; this._seller = _seller; this._amount = _amount; this._memo = _memo; this._timestamp = _timestamp; } public Transaction() { _id = 0; _buyer = ""; _seller = ""; _amount = 0.0; _memo = ""; _timestamp = ""; } public int getId() { return _id; } public String getBuyer() { return _buyer; } public String getSeller() { return _seller; } public double getAmount() { return _amount; } public String get_memo() { return _memo; } public String get_timestamp() { return _timestamp; } @Override public String toString() { return "ID: " + this.getId() + ", " + "Buyer: " + this.getBuyer() + ", " + "Seller: " + this.getSeller() + ", " + "Amount: $" + this.getAmount() + ", " + "Memo: " + this.get_memo() + ", " + "Timestamp: " + this.get_timestamp(); } //Implement the Comparable interface for the Transaction class so that the items in // the Project 4b TransactionManager collection can be sorted before being returned // by the various methods. This means that you must supply a compareTo method. @Override public int compareTo(PurchaseReceipt purchaseReceipt) { return (int) (this.getAmount() - purchaseReceipt.getAmount()); } } ________________________________________________________________________________
public class GoldTransaction extends Transaction { public int _carats; public double _weight; public GoldTransaction() { super(); } public GoldTransaction(int _id, String _buyer, String _seller, double _amount, String _memo, String _timestamp, int _carats, double _weight) { super(_id, _buyer, _seller, _amount, _memo, _timestamp); this._carats = _carats; this._weight = _weight; } public int get_carats() { return _carats; } public double get_weight() { return _weight; } @Override public String toString() { return "ID: " + this.getId() + ", " + "Buyer: " + this.getBuyer() + ", " + "Seller: " + this.getSeller() + ", " + "Amount: $" + this.getAmount() + ", " + "Memo: " + this.get_memo() + ", " + "Carats: " + this.get_carats() + ", " + "Weight: " + this.get_weight() + ", " + "Timestamp: " + this.get_timestamp(); } } ________________________________________________________________________________
public class LumberTransaction extends Transaction { private int _grade; private double _weight; public LumberTransaction() { super(); } public LumberTransaction(int _id, String _buyer, String _seller, double _amount, String _memo, String _timestamp, int _grade, double _weight) { super(_id, _buyer, _seller, _amount, _memo, _timestamp); this._grade = _grade; this._weight = _weight; } public int get_grade() { return _grade; } public double get_weight() { return _weight; } @Override public String toString() { return "ID: " + this.getId() + ", " + "Buyer: " + this.getBuyer() + ", " + "Seller: " + this.getSeller() + ", " + "Amount: $" + this.getAmount() + ", " + "Memo: " + this.get_memo() + ", " + "Grade: " + this.get_grade() + ", " + "Weight: " + this.get_weight() + ", " + "Timestamp: " + this.get_timestamp(); } } TransactionManager col : ArrayList-PurchaseReceipt + add(PurchaseReceipt) + clear() +getCount(): int +getAll): ArrayList-PurchaseReceipt +findBuyer(String buyer) ArrayList PurchaseReceipt +findSeller(String seller) ArrayList PurchaseReceipt +findld(int id): PurchaseReceipt + save() +load() Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
