Composite Design-Pattern Amazon Payment Lines

package PaymentManager;

public class Order {
  String reference;
  double value;

  Order(String r, double v){
      reference = r;
      value = v;
  }
  String getReference() {
     return reference;
  }
  double getValue() {
     return value;
  }
  public String toString() {
      return reference;
  }
}


public class Payment {
  Payment pay;
  Order[] orders;
  String order_type;
  Payment(Payment p, Order[] o, String type ) {
      this(o, type);
      this.pay = p;
  }

  Payment(Order[] o, String type) {
      orders = o;
      order_type =type;
  }
  String getOrderType() {
      return order_type;
  }
  Payment getPayment() {
      return pay;
  }
  Order[] getOrders() {
      return orders;
  }
  public String toString() {
      return "Order Type -> " +order_type;
  }
}


public class OrderTestRun {
  public static void main(String[] args) {
  Order[] detail = {
      new Order("AMZ-SUB-001", 15.00),
      new Order("AMZ-SUB-002", 15.00)
            };
      Payment p1 = new Payment(detail, "Amazon Order Lines");
     
      Order[] total = {
      new Order("AMZ-001", 30.00)
            };
     
      Payment p2 = new Payment(p1,total, "Amazon Order Total");
 
      System.out.println(p2);
      Order[] ord = p2.getOrders();
      if (ord != null)
            for (int k = 0; k < ord.length; k++)
                 System.out.println("Order Reference: "+ord[k]+" Value: €"+ ord[k].getValue());      
           
      Payment p = p2.getPayment();
      System.out.println(" " + p);
      if (p!= null) {
         Order[] ords = p.getOrders();
         if (ords != null)
            for (int k = 0; k < ords.length; k++)
                 System.out.println("Order Reference: "+ords[k]+" Value: €"+ ords[k].getValue());
     
      }  
  }
}

Comments

  1. Nice blog. Thank you for sharing. The information you shared is very effective for learners I have got some important suggestions from it. erp providers in chennai.

    ReplyDelete
  2. The best thing is that your blog really informative thanks for your great information!
    erp in chennai

    ReplyDelete
  3. I found a lot of interesting information here. A really good post
    office 2011 mac download deutsch

    ReplyDelete

Post a Comment

Popular posts from this blog

Basic Send Message to MQ with Java and IBM MQ JMS

Basic Receive Message to MQ with Java and IBM MQ JMS

Creating a simple Alert / Success Message with ASP.NET/VB using Bootstrap