[text] prac4

Viewer

  1. package prac4;
  2.  
  3. public class Inventory {
  4.  
  5.         public static void main(String[] args) {
  6.                  Product p1 = new Product(1, "ssoap", 40, "household", 45); 
  7.                  Product p2 = new Product(2, "goil", 50, "household", 45);   
  8.                  Product p3 = new Product(3, "mtv", 7000, "electronics", 100); 
  9.                  Product p4 = new Product(4, "xrefrigerator", 20000, "electronics", 45);
  10.                  Product p5 = new Product(5, "mmobile", 3500, "gadgets", 65);   
  11.                  Product[] prods = {p1,p2,p3,p4,p5};
  12.                  
  13.                    int count1 =  Inventory.updateProductQuantity(prods, 55);  
  14.                    System.out.println("Updated count "+count1);     
  15.                    Product[] prods1 =     Inventory.getAllProductsProducttypeCost(prods, "household");  
  16.                    for(Product prod : prods1)
  17.                    {   
  18.                            if(prod!=null)
  19.                            {  
  20.                                    System.out.println(prod.getProductname()+" "+prod.getProductcost()+" "+prod.getProductquantity()+" "+prod.getProducttype());  
  21.                                    } 
  22.                            }
  23.                    }
  24. public static int updateProductQuantity(Product[] prd, int st)
  25. {int count=0;
  26.         for(int i=0;i<prd.length;i++)
  27.         {
  28.                 if(prd[i].getProductquantity()<100)
  29.                 {
  30.                         //prd[i].setProductquantity(55);
  31.                         count++;
  32.                 }
  33.         }
  34.         return count;
  35. }
  36. public static Product[] getAllProductsProducttypeCost(Product[] pr,String st)
  37. {int cnt=0;
  38.         for(int i=0;i<pr.length;i++)
  39.         {
  40.                 if(pr[i].getProductcost()<1000)
  41.                 {
  42.                         cnt++;
  43.                 }
  44.         }
  45.         Product[] prs=new Product[cnt];
  46.         int j=0;
  47.         for(int i=0;i<pr.length;i++)
  48.         {
  49.                 if(pr[i].getProductcost()<1000)
  50.                 {
  51.                         prs[j]=pr[i];
  52.                         j++;
  53.                 }
  54.         }
  55.         return prs;
  56. }
  57.         }
  58.  
  59.  

Editor

You can edit this paste and save as new: