Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Directions: Complete program in Java. Thank you! You\'ve been hired by Biggy\'s

ID: 3778056 • Letter: D

Question

Directions: Complete program in Java. Thank you!

You've been hired by Biggy's Popcorn to write a Java console application that handles popcorn orders at their store. The application has the following two classes orderjava This class represents a customer in line who wants to buy popcorn and includes: Fields static totalOrderAmount count of all popcorn bags sold orderAmount the number of popcorn bags the customer wants. next- a pointer to the next Order in the queue. A constructor with no parameters that sets the fields, respectively, to these values: order Amount--1 next null A constructor with two parameters that sets the fields, respectively, to these values: totalOrder Amount totalOrderAmount order Amount orderAmount set from parameter next set from parameter Getter methods for each field declare the getter for totalQrderAmount static). Setter methods for each non-static field (declare the setter for equals method that compares order amounts for equality toString method for returning the order amount only.

Explanation / Answer

public class order

{

//These are the attributes (fields) of the class. It's good practice to make them

//private so that they can only be accessed from within the class.

private String name;

private BigDecimal cost;

public order(String name, BigDecimal cost)

{

    this.name = name;

   this.cost = cost;

}

public BigDecimal getCost()

{

    return this.cost;

}

public String getName()

{

    return this.name;

}

}

public class Order

{

private Map<Beverage, Integer> beverages = new HashMap<Beverage, Integer>();

public BigDecimal getTotal()

{

    BigDecimal total = BigDecimal.ZERO;

    //Loop over all the order that have been added to the map summing the cost.

    for (order order : this.order.keySet())

    {

      //Convert the quantity in the map to a BigDecimal needed for the multiply method.

      BigDecimal quantity = new BigDecimal(this.oreder.get(order));

      total = total.add(order.getCost().multiple(quantity));

    }

    return total;

}

public void add(order order, Integer quantity)

{       

    //Store the quantity against the order.

    this.order.put(order, quantity);

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote