All pastes #478228 Raw Edit

Untitled

public text v1 · immutable
·published 2007-05-09 01:28 UTC
rendered paste body
public class Order
{
   
   // Complete this class according to the instructions in TMA02 Q2
   
   // Instance variable and constant declarations should go here
   private int currentSize;
   private static int MAX_ORDERS = 10;
   private Product[] products;

   // The constructor should go here
   public Order()
   {
       currentSize = 0;
       products = new Product[MAX_ORDERS];    
   }
   // The public methods should go here
   public int getCurrentSize()
   {
       return products.length;
   }
   
   public void add(Product aProduct)
   {      
       products[currentSize] = aProduct;
       currentSize++;
   }
   
   public void displayProducts()
   {
       for (int i = 0; i < products.length; i++)
       {
          System.out.println(products[i]);
       }
   }
}

 */
public class TestOrder
{
   public static void main(String[] args)
   {    
      // Create three Product instances
      Product p1 = new Product("Tea set", "6 cups, saucers and side plates.", 2431);
      Product p2 = new Product("Coaster set", "6 decorative coasters.", 199);
      Product p3 = new Product("Kitchen memo pad", "Magnetic jotter for fridge.", 95);
      
      Product p4 = new Product("Salt shaker", "Silver effect salt shaker.", 110);
      Product p5 = new Product("Pepper shaker", "Silver effect pepper shaker, shop soiled.", 10);
      Product p6 = new Product("Pepper shaker", "Silver effect pepper shaker.", 105);
      Product p7 = new Product("Fridge magnet", "Pointless fridge magnet", 5);
      
      // Create an Order instance
      Order o1 = new Order();
      
      // Check the size
      System.out.println("Size of order: " + o1.getCurrentSize());
      
      // Add three items to the order
      o1.add(p1);
      o1.add(p2);
      o1.add(p3);
      o1.add(p4);
      o1.add(p5);
      o1.add(p6);
      o1.add(p7); 
}