Question

Please create two tests classes for the code down below that use all of the methods...

Please create two tests classes for the code down below that use all of the methods in the Transaction class, and all of the non-inherited methods in the derived class. Overridden methods must be tested again for the derived classes. The first test class should be a traditional test class named "Test1" while the second test class should be a JUnit test class named "Test2". All I need is to test the classes, thanks!

  1. Use a package that contains the Transaction class and its derived classes. Use this package statement:
    package it313.proj4.<<your username>>;
    
    The Test1 and Test2 classes should not be placed in this package.
  2. You may use Eclipse to generate your constructors, getters, and toString methods for your classes. Recall how to set Eclipse to use the underscore ( _) prefix for instance variables and a prefix for the parameters, such as the if you want one.
  3. Instance variable information:
    Class Instance
    Variable
    Information
    Transaction _id 4 digit value identifying the transaction
    Transaction _seller Person or organization selling the commodity
    Transaction _buyer Person or organization buying the commodity
    Transaction _amount Amount paid for the commodity
    Transaction _memo Details about the transaction
    Transaction _timestamp Date and time of the transaction
    GoldTransaction _carats Purity of the gold, value from 1 to 24
    GoldTransaction _weight Weight of gold sold in grams
    LumberTransaction _grade Grade of lumber, value from 1 (best) to 4
    LumberTransaction _weight Weight of lumber sold in tons
  4. The Transaction class implements the PurchaseReceipt interface, which inherits from the Comparable interface. This means that in addition to supplying the methods getId, getBuyer, getSeller, and getAmount, a compareTo method must be supplied. It should return 1 if this._id > other._id, it should return -1 if this._id > other._id; it should return 0 if this._id == other._id. Test the compareTo method in theTransaction class to make sure that its objects are compared correctly.
  • Implement and test the base class Transaction, and the derived classes GoldTransaction, and LumberTransaction.
  1. 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.
  2. 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.
This is the code:
public interface PurchaseReceipt extends Comparable {

    public int getId();

    public String getBuyer();

    public String getSeller();

    public double getAmount();

}

________________________________________________________________________________

//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();
    }
}
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hey Friend,

Here are the classes you will be needing, I ran out of time writing all the classes, what is now left is to write a test class and instructed and should be pretty straightforward.

Let me know for any questions.

Thank you, and please do give a thumbs up !!

________________________________________________________________________________

public interface PurchaseReceipt extends Comparable<PurchaseReceipt> {

    public int getId();

    public String getBuyer();

    public String getSeller();

    public double getAmount();

}

________________________________________________________________________________

//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();
    }
}
Add a comment
Know the answer?
Add Answer to:
Please create two tests classes for the code down below that use all of the methods...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Implement the classes in the following class diagram. The Book class implements the Comparable interface. Use impl...

    Implement the classes in the following class diagram. The Book class implements the Comparable interface. Use implements Comparable<Book> in the class definition. Now, all book objects are instances of the java.lang.Comparable interface. Write a test program that creates an array of ten books. 1. Use Arrays.sort( Book[]l books) from the java.util package to sort the array. The order of objects in the array is determined using compareTo...) method. 2. Write a method that returns the most expensive book in the...

  • The current code I have is the following: package uml; public class uml {        public...

    The current code I have is the following: package uml; public class uml {        public static void main(String[] args) {              // TODO Auto-generated method stub        } } class Account { private String accountID; public Account(String accountID) { this.accountID = accountID; } public String getAccountID() { return accountID; } public void setAccountID(String accountID) { this.accountID = accountID; } @Override public String toString() { return "Account [accountID=" + accountID + "]"; } } class SuppliesAccount extends Account { private...

  • Java file Name Dog Classes and Methods Create a constructor that incorporates the type, breed, and...

    Java file Name Dog Classes and Methods Create a constructor that incorporates the type, breed, and name variables (do not include topTrick). Note: The type refers to what the breed typically does; for example, a corgi would be a “cattle herding dog.” A Shiba Inu would be a “hunting dog.” Create the setTopTrick() mutator method Dog is parent class Corgi and Driver are subclasses Complete the Corgi class: Using the UML Class diagram, declare the instance variables. Create the two...

  • Can the folllowing be done in Java, can code for all classes and code for the...

    Can the folllowing be done in Java, can code for all classes and code for the interface be shown please. Modify the GeometricObject class to implement the Comparable interface and define a static max method in the GeometriObject class for finding the larger of two GeometricObject objects. Write a test program that uses the max method to find the larger of two circles, the larger of two rectangles. The GeometricObject class is provided below: public abstract class GeometricObject { private...

  • I need help to write a test case. 1. Go to the ConcertTicketTest.java file and write...

    I need help to write a test case. 1. Go to the ConcertTicketTest.java file and write test cases for the compareTo method you just implemented. /* ConcertTicket.java file */ package SearchingSorting; /** * * @author clatulip */ public class ConcertTicket implements Comparable<ConcertTicket> { private String name; private int price; private char row; private int seat; public ConcertTicket(String name, int price) { this.name = name; this.price = price; // randomly create a row and seat // assumes 60 seats across width...

  • JAVA The Comparable interface is defined as follows: public interface Comparable<T> {         int compareTo(T other);...

    JAVA The Comparable interface is defined as follows: public interface Comparable<T> {         int compareTo(T other); } A Film class is defined as public class Film {      private String title;      private int yearOfRelease;           public Film(String title, int yearOfRelease) {           super();           this.title = title;           this.yearOfRelease = yearOfRelease;      }           public void display()      { System.out.println("Title " + title +". Release" + yearOfRelease);      } } Rewrite the Film class so that it...

  • create a Person class with two fields (name(String), age(int)) create all the required methods such as...

    create a Person class with two fields (name(String), age(int)) create all the required methods such as the accessors, mutators, toString(),constructors etc. Use the comparable interface and implement the compareTo method such that the person objects can be compared and sorted according to their age.

  • How to solve and code the following requirements (below) using the JAVA program? 1. Modify the...

    How to solve and code the following requirements (below) using the JAVA program? 1. Modify the FoodProduct Class to implement Edible, add the @Overrride before any methods that were there (get/set methods) that are also in the Edible interface. 2. Modify the CleaningProduct Class to implement Chemical, add the @Overrride before any methods that were there (get/set methods) that are also in the Chemical interface. 3. Create main class to read products from a file, instantiate them, load them into...

  • Receiveing this error message when running the Experts code below please fix ----jGRASP exec: javac -g...

    Receiveing this error message when running the Experts code below please fix ----jGRASP exec: javac -g GeometricObject.java GeometricObject.java:92: error: class, interface, or enum expected import java.util.Comparator; ^ 1 error ----jGRASP wedge2: exit code for process is 1. ----jGRASP: operation complete. 20.21 Please code using Java IDE. Please DO NOT use Toolkit. You can use a class for GeometricObject. MY IDE does not have access to import ToolKit.Circle;import. ToolKit.GeometricObject;.import ToolKit.Rectangle. Can you code this without using the ToolKit? Please show an...

  • FOR JAVA: Summary: Create a program that adds students to the class list (see below). The...

    FOR JAVA: Summary: Create a program that adds students to the class list (see below). The solution should be named Roster402_v2.java. Allow the user to control the number of students added to the roster. Ask if the user would like to see their new roster to confirm additions. If yes, then display contents of the file, if no, end the program. ------------------------------------------------------------------------------------- List of student names and IDs for class (this will be your separate text file): Jones, Jim,45 Hicks,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT