FileDocCategorySizeDatePackage
BurritoInventoryProducer.javaAPI DocExample1406Tue Jan 25 10:45:14 GMT 2000None

BurritoInventoryProducer.java

import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class BurritoInventoryProducer extends HttpServlet {

  // Get (and keep!) a reference to the shared BurritoInventory instance
  BurritoInventory inventory = BurritoInventory.getInstance();

  public void doGet(HttpServletRequest req, HttpServletResponse res)
                               throws ServletException, IOException {
    res.setContentType("text/html");
    PrintWriter out = res.getWriter();

    out.println("<HTML>");
    out.println("<HEAD><TITLE>Burrito Inventory Producer</TITLE></HEAD>");

    // Produce random amounts of each item
    Random random = new Random();

    int cheese = Math.abs(random.nextInt() % 10);
    int rice = Math.abs(random.nextInt() % 10);
    int beans = Math.abs(random.nextInt() % 10);
    int chicken = Math.abs(random.nextInt() % 10);

    // Add the items to the inventory
    inventory.addCheese(cheese);
    inventory.addRice(rice);
    inventory.addBeans(beans);
    inventory.addChicken(chicken);

    // Print the production results
    out.println("<BODY>");
    out.println("<H1>Added ingredients:</H1>");
    out.println("<PRE>");
    out.println("cheese: " + cheese);
    out.println("rice: " + rice);
    out.println("beans: " + beans);
    out.println("chicken: " + chicken);
    out.println("</PRE>");
    out.println("</BODY></HTML>");
  }
}