dataabstraction.zip

DataAbstraction/Invoice.java

DataAbstraction/Invoice.java

    import  java . util . * ;

    public   class   Invoice   extends   Transaction
    {
    //  Add a true/false variable - 'isPaid'...
     
         
   
    //  Add an Explicit Value Constructor.
     //   Parameters: int tranID, int customer, boolean paid
     //   Note 'tranID' is private to the Item class
 
 
 
 
 
   
    //  Add an 'addItem' method here.
     //   The method creates a new InvoiceItem object and adds it to the ArrayList
     //    inherited from the Transaction class.
     //   Parameters: int itemID, String desc, double price, int qty, int ounces







    //  Override toString here.
    //   Return value must include 'tranID' from Transaction, 'isPaid' 
     //   and listing of InvoiceItems...
    //   See example output in output.txt.







    }

DataAbstraction/InvoiceItem.java

DataAbstraction/InvoiceItem.java


    public   class   InvoiceItem   extends   Item
    {
    
    //  Add variable 'ouncesPerUnit' as an int...



   
    //  Add constructor.  
    //   Parameters are: int itemID, String description, double price, int quantityOrdered, int ouncesPerUnit





   
    //  Add 'changeInventory' method...
     //   The method creates a String that reports the processing that would take place.
     //   See example output in output.txt




   
   
    //  Override 'toString' method here.
     //   Return 'toString' from Item class plus the ounces per unit...




   
   
    }

DataAbstraction/Item.class

public abstract synchronized class Item {
    protected int itemID;
    protected String description;
    protected double unitPrice;
    protected int quantity;
    public void Item(int, String, double, int);
    protected abstract String changeInventory();
    public String toString();
}

DataAbstraction/Item.java

DataAbstraction/Item.java


//  Item class - do not change anything in this class
 
public   abstract   class   Item
{
     protected   int  itemID ;
     protected   String  description ;
     protected   double  unitPrice ;
     protected   int  quantity ;
    
     public   Item ( int  itemID ,   String  description ,   double  unitPrice ,   int  quantity )
     {
         this . itemID  =  itemID ;
         this . description  =  description ;
         this . unitPrice  =  unitPrice ;
         this . quantity  =  quantity ;
     }

     protected   abstract   String  changeInventory ();
    
    @ Override
     public   String  toString ()
     {
         return   "\tItem: "   +  itemID  +   " - "   +  description  +
                 " Quantity: "   +  quantity  +   ", Cost: "   +  unitPrice  *  quantity ;
     }

}

DataAbstraction/output.txt

Purchase order#: 102, Date: Sat Apr 27 hh:mm:ss PDT YYYY Vendor: 501 Status: Approved Item: 24 - Lumia 300 Quantity: 2, Cost: 866.0 Markup: 2.0 Item: 86 - iPhone 4S Quantity: 1, Cost: 721.5 Markup: 1.75 Quantity on hand has been increased for Lumia 300 by 2 Quantity on hand has been increased for iPhone 4S by 1 Purchase order#: 101, Date: Sat Apr 27 hh:mm:ss PDT YYYY Vendor: 502 Status: Pending Item: 42 - Lumia 900 Quantity: 2, Cost: 850.0 Markup: 1.5 Quantity on hand has been increased for Lumia 900 by 2 Invoice#: 202, Date: Sat Apr 27 hh:mm:ss PDT YYYY Customer: 901 Paid: true Item: 681 - Lumia 822 Quantity: 3, Cost: 1411.5 Ounces: 4 Item: 199 - HTC One Quantity: 1, Cost: 389.0 Ounces: 5 Item: 1255 - Samsung Flash Quantity: 2, Cost: 250.0 Ounces: 3 Inventory has been relieved for Lumia 822 by 3 Inventory has been relieved for HTC One by 1 Inventory has been relieved for Samsung Flash by 2 Invoice#: 201, Date: Sat Apr 27 hh:mm:ss PDT YYYY Customer: 902 Paid: false Item: 1255 - Samsung Flash Quantity: 2, Cost: 250.0 Ounces: 5 Item: 198 - HTC m7 Quantity: 1, Cost: 533.0 Ounces: 4 Inventory has been relieved for Samsung Flash by 2 Inventory has been relieved for HTC m7 by 1

DataAbstraction/PO.class

public synchronized class PO extends Transaction {
    private String status;
    public void PO(int, int, String);
    public void addItem(int, String, double, int, double);
    public String toString();
}

DataAbstraction/POItem.class

public synchronized class POItem extends Item {
    double markUp;
    public void POItem(int, String, double, int, double);
    protected String changeInventory();
    public String toString();
}

DataAbstraction/Tester.java

DataAbstraction/Tester.java

//  Tester class.  Do not change anything in this class.

/*  Tasks for the data abstraction section:
 *   - Add code to the 'Transaction' class to implement the Comparable interface
 *   - Complete the InvoiceItem and Invoice classes
 *      (See comments in the InvoiceItem.java and Invoice.java)
 *  See also the Item.java class and expected output in output.txt
 *  Note your output will vary slightly for the data stamp - hh:mm:ss
 */
import  java . util . * ;
public   class   Tester
{
     public   static   void  main ( String []  args )
     {
         Transaction []  trans  =   new   Transaction [ 4 ];
        PO po ;
         Invoice  iv ;
        
        po  =   new  PO ( 101 ,   502 ,   "Pending" );
        po . addItem ( 42 ,   "Lumia 900" ,   425.00 ,   2 ,   1.50 );
        trans [ 3 ]   =  po ;
        
        po  =   new  PO ( 102 ,   501 ,   "Approved" );
        po . addItem ( 24 ,   "Lumia 300" ,   433.00 ,   2 ,   2.0 );
        po . addItem ( 86 ,   "iPhone 4S" ,   721.50 ,   1 ,   1.75 );
        trans [ 2 ]   =  po ;
        
        iv  =   new   Invoice ( 201 ,   902 ,   false );
        iv . addItem ( 1255 ,   "Samsung Flash" ,   125.00 ,   2 ,   5 );
        iv . addItem ( 198 ,   "HTC m7" ,   533.00 ,   1 ,   4 );
        trans [ 1 ]   =  iv ;
        
        iv  =   new   Invoice ( 202 ,   901 ,   true );
        iv . addItem ( 681 ,   "Lumia 822" ,   470.50 ,   3 ,   4 );
        iv . addItem ( 199 ,   "HTC One" ,   389.00 ,   1 ,   5 );
        iv . addItem ( 1255 ,   "Samsung Flash" ,   125.00 ,   2 ,   3 );
        trans [ 0 ]   =  iv ;
        
         //  This call to Arrays.sort will require implementation of the
         //  Comparable interface in the Transaction class...
         Arrays . sort ( trans );
        
         for   ( Transaction  t  :  trans )
         {
             //  Show formatted PO's and invoices...
             System . out . println ( t );
            
             //  Process inventory...
             for   ( Item  i  :  t . getItems ())
             {
                 System . out . println ( "\t"   +  i . changeInventory ());
             }
         }
     }
}

DataAbstraction/Transaction.java

DataAbstraction/Transaction.java

import  java . util . * ;
/*  Modify this source code in the space indicated only!
 *
 *  Implement the Comparable interface in this class (see below)...
 */   

 
public   abstract   class   Transaction              // <--  Your code goes here
{
     // Note the tranID variable is private - do not change
     private     int   tranID ;
     protected   int   participantID ;
     protected   Date  tranDate ;
     protected   ArrayList < Item >  items ;
    
     public   Transaction ( int  tranID ,   int  participantID )
     {
         this . tranID  =  tranID ;
         this . participantID  =  participantID ;
         this . tranDate  =   Calendar . getInstance (). getTime ();
        items  =   new   ArrayList < Item > ();
     }

     protected   final   ArrayList < Item >  getItems ()
     {
         return   this . items ;
     }

     /*  Implement the Comparable interface here.
     *  Sort first by participantID and if the participantID's are the
     *  same, sort by tranID.
     */
     
      //  Your code goes here...
     
     
       
    
    
    
    
    @ Override
     public   String  toString ()
     {
         return  tranID  +   ", Date: "   +  tranDate ;
     }
    
}