arvind
restrictedproduct
0 Answer(s)      4 years and a month ago
Posted in : Java Beginners
<p>import java.util.*; //Use of ArrayList
import java.io.*; //Use of InputStreamReader and BufferedReader
import java.util.regex.*; //Use of regular expressions
import java.text.*;</p>

<p>class ProductController
{
  OrderController orderControllerOb=new OrderController();</p>

<p>  public void initiateReportOnProductsManufactured()
   {
     BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
     OrderUI orderUI=new OrderUI();
     ProductUI productUI=new ProductUI();
     Order orderOb=null;
     ArrayList&lt;Object> orderDetails=new ArrayList&lt;Object>();
     int orderId=orderUI.getOrderId();
     if(orderId!=-1) //If system error occurs
     {
      orderOb=CDAManufacturers.searchOrderList(orderId); //Check order id is in the order list
      if(orderOb!=null) //If order id is in the order list
      {
        orderDetails=CDAManufacturers.returnOrderDetails(orderOb); //Fetch order details from the order list
        productUI.displayOrderDetails(orderDetails); //Display order details
        orderUI.displayMenu(); //clerk's menu is displayed
      }
      else
      {
        orderUI.displayErrorMessage("Invalid order ID!!!!");
        orderUI.displayMenu(); //clerk's menu is displayed
      }
    }
    else
    {
      orderUI.displayErrorMessage("Sorry!!! unable to display the order details");
      orderUI.displayMenu(); //clerk's menu is displayed
    }
  }
  public void initiateReportOnTaxCollected()
  {
    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    OrderUI orderUI=new OrderUI();
    Order orderOb=null;
    double bill=0.0,salesTax=0.0,octroi=0.0,customsDuty=0.0;
    ArrayList&lt;Object> orderDetails=new ArrayList&lt;Object>();
    int orderId=orderUI.getOrderId();
    if(orderId!=-1) //If system error occurs
    {
      orderOb=CDAManufacturers.searchOrderList(orderId); //Check order id is in the order list
      if(orderOb!=null) //If order id is in the order list
      {
        orderDetails=CDAManufacturers.returnOrderDetailsForBill(orderOb); //Fetch order details from the order list
        bill=CDAManufacturers.calculateBill(orderDetails);
        salesTax=0.1*bill;
        octroi=0.14*bill;
        customsDuty=0.16*bill;
        System.out.println("Rs."+salesTax);
        System.out.println("Rs."+octroi);
        System.out.println("Rs."+customsDuty);
        orderUI.displayMenu(); //clerk's menu is displayed
      }
      else
      {
        orderUI.displayErrorMessage("Invalid order ID!!!!");
        orderUI.displayMenu(); //clerk's menu is displayed
      }
    }
    else
    {
      orderUI.displayErrorMessage("Sorry!!! unable to display the order details");
      orderUI.displayMenu(); //clerk's menu is displayed
    }
  }</p>

<p>public void initiateReportOnRevenueEarned()
  { <br />
  orderControllerOb.initiateViewBills();
  }
public void initiateReportOnProductsReturned()
  {
  }
  public void initiateViewSalesOfProducts()
  {
    ProductUI productUiOb=new ProductUI(); //Create ProductUI
    ArrayList&lt;Product> productList=new ArrayList&lt;Product>();
      productList=CDAManufacturers.returnSalesOfProducts(); //Returns list of sales of Products
      productUiOb.viewProductSalesList(productList); //Displays list of sales of Products
    }
  }</p>

<p>//---------------------------------------------------------------------------------</p>

<p>class ProductUI
{
  private InputStreamReader input=new InputStreamReader(System.in);
  private BufferedReader br=new BufferedReader(input);</p>

<p>  //Contract: ProductSalesList(List):void
  //Displays product id, product name and sales count of the product for given product list
  public void viewProductSalesList(ArrayList&lt;Product> productList)
  {
    System.out.println(" Product\t\t------------Sales-----------");
    System.out.println("");
    for(Product productOb:productList)
      System.out.println(productOb.getProductName()+"\t\t\t\t"+productOb.getProductSalesCount());
    displayMenu(); //Display administrator's menu
  }</p>

<p>  //Contract: displayErrorMessage(String):void
  //Displays error message and then the administrator's menu
  public void displayErrorMessage(String msg)
  {
    System.out.println(msg);
    displayMenu(); //Display administrator's menu
  }</p>

<p>  //Contract: displayMenu():void
  //Displays administrator's menu
  public void displayMenu()
  {
    try
    {
      System.out.println("");
      System.out.println("Press any key to continue");
      br.readLine();
      MainClerkSystem mainclerkSystemOb=new MainClerkSystem();
      mainclerkSystemOb.initiateClerkView();
    }
    catch(Exception e)
    {
      System.err.println("Exception: "+e);
    }
  } </p>

<p>  //Contract: requestProductDetailsConfirmation():String
  //Reads the product details and validates them
  private String requestProductDetailsConfirmation()
  {
    String cont="";
    boolean flag=false;
    try
    {
      while(flag==false)
      {
        System.out.println("");
        System.out.println("Are you sure you want to add product? (Y/N): ");
        cont=br.readLine();
        if(cont.equalsIgnoreCase("y")||cont.equalsIgnoreCase("n"))
          flag=true;
        else
          System.out.println("Please enter Y or N...");
      }
      return(cont);
    }
    catch(Exception e)
    {
      //System.err.println("Exception: "+e);
      return("n");
    }
  }</p>

<p>  //Contract: notifyProductAdditionSuccess(Object):void
  //Prompt product's successfully addition and display its id
  public void notifyProductAdditionSuccess(Product productOb)
  {
      displayMenu();
  }</p>

<p>  //Contract:displayOrderDetails(List):void
  //Displays the order details which is passed as a list
  public void displayOrderDetails(ArrayList&lt;Object> orderDetails)
  {
    System.out.println("");
    System.out.println("Date Of Order :\t"+orderDetails.get(3));
    int x=((orderDetails.size()-4)/2);
    System.out.println("");
    System.out.println("Quantity Manufactured \t Products Name");
    for(int i=5;i<orderDetails.size()-x;i++)
    {
      System.out.println("\t"+orderDetails.get(i+x)+"\t\t"+orderDetails.get(i));
    }
  } <br />
}</p>

<p>//----------------------------------------------------------------------------------------</p>

<p>//Class Product:
//Attributes: int id ; String name ; int quantity ; double price ; int salesCount
//Methods:    setProductId(List):void ; getProductId():list ; setProductName(String):void ; getProductName():String
//            setProductQuantity(String):void ; getProductQuantity():int ; setProductPrice(double):void 
//            getProductPrice():double ; setProductSalesCount(int):void ; getProductSalesCount():int
class Product
{
  private int id;
  private String name;
  private int quantity;
  private double price;
  private int salesCount;</p>

<p>  //Contract: setProductId(int):void
  //It modifies Product id
  public void setProductId(int id)
  {
    this.id=id;
  }</p>

<p>  //Contract: getProductId():int
  //It returns Product id
  public int getProductId()
  {
    return(id);
  }
  //Contract: setProductName(String):void
  //It modifies product name
  public void setProductName(String name)
  {
    this.name=name;
  }</p>

<p>  //Contract:getProductName():String
  //It returns product name
  public String getProductName()
  {
    return(name);
  }</p>

<p>  //Contract: setProductQuantity(String):void
  //It modifies product name
  public void setProductQuantity(int quantity)
  {
    this.quantity=quantity;
  }</p>

<p>  //Contract:getProductQuantity():int
  //It returns product name
  public int getProductQuantity()
  {
    return(quantity);
  }
  //Contract: setProductPrice(double):void
  //It modifies product price
  public void setProductPrice(double price)
  {
    this.price=price;
  }</p>

<p>  //Contract:getProductPrice():double
  //It returns product price
  public double getProductPrice()
  {
    return(price);
  }</p>

<p>  //Contract: setProductSalesCount(int):void
  //It modifies product sales count
  public void setProductSalesCount(int salesCount)
  {
    this.salesCount=salesCount;
  }</p>

<p>  //Contract:getProductSalesCount():int
  //It returns product sales count
  public int getProductSalesCount()
  {
    return(salesCount);
  }
}</p>
Advertisement
View Answers









Related Tutorials/Questions & Answers: