import java.util.Date; // used to manipulate dates - we will get to this later in the course
// note that for this example, we are using Javadoc type comments.  Using a /** */ to enclose
// our descriptions, and the special key words @param @return, we can then run javadoc and
// full documentation for our program will be generated.  (either from tools-> preview, or using Javadoc)
/** a class of methods to print the order
 *  for Joe's Pizzeria.
 */
class JoesOrderSystem {
  private static float invoiceTotal; // a class variable used to maintain the running
  // total for the invoice.
  /** Print out a customer order for Joe's Pizzeria
   */
  public static void main(String[] args) {
    invoiceTotal = 0.0f;  /* if you assign a constant value to a float, you should append
                             an f to the value.  See the text on float constants.
                          */
    int qty = 0;
    float cost = 0.0f;
    String detail = "";
    String desc = "";
    //Lets get the order items and print them.
    // prompt for detail information - then send it to the formatter/printer
    int nbrItems = 0;
    do {
      System.out.print("enter the quantity of items: ");
      qty = In.getInt();
      if (qty > 0) {
        System.out.print("enter the description of item: ");
        desc = In.getString();
        System.out.print("enter the cost per item: ");
        cost = In.getFloat();
        detail += getDetail( qty,  desc, cost) + "\n";
        // printDetail( qty,  desc, cost);
      }
    } while (qty > 0);
    printHeading(); // this statement invokes the method printHeading() above.
    // it is executed.
    
    System.out.println(detail);
    printTotal();
  }
  
  /** Print the heading for each order.
   *  The heading consists of "Welcome to Joe's Pizzeria", 
   *  "10 King's College Circle", "Toronto",
   *  and the order date/time.
   */
  public static void printHeading() {
    System.out.println("Welcome to Joe's Pizzeria");
    System.out.println("10 King's College Circle");
    System.out.println("Toronto");
    System.out.println((new Date()).toString()); // we will get to this later in the course
    System.out.println("\n");
  }
  // example of a method that accepts parameters
  /** Calculate the total for a line item equal to the cost per item, times the quantity, 
   *  then, print an order detail.
   *  @param q the number of items ordered.
   *  @param d the description of the item.
   *  @param c the cost of each item.
   */
  public static void printDetail(int q, String d, float c) {
    float total = c * q;
    System.out.println(q + "\t" + d + "\t" + c + "\t" + total);
  }
  // example of a method that returns a value  
  // redo the method so that it returns a string, which can be printed later.
  /** Calculate the total for a line item equal to the cost per item, times the quantity, 
   *  then, return the order detail.
   *  @param q the number of items ordered.
   *  @param d the description of the item.
   *  @param c the cost of each item.
   *  @return the formatted order detail
   */
  public static String getDetail(int q, String d, float c) {
    String result = q + "\t" + d + "\t" + c + "\t" + (c * q);
    addToTotal(q, c); /* in order to prevent tight coupling of methods, this invocation
                         should be called from the main method.  That way, the methods
                         remain independent of each other.  So take this line, and
                         put it in the main method. Be sure to call with qty and cost.
                      */    
    return result;
  }
  /** Calculate the total for a line item equal to the cost per item, times the quantity, 
   *  then, return the value.
   *  @param q the number of items ordered.
   *  @param c the cost of each item.
   */
  public static void addToTotal(int q, float c) {
    invoiceTotal += q*c;
  }
  /** Print the invoice total. */
  public static void printTotal() {
    System.out.println("Please pay $" + invoiceTotal);
  }
  
}

