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

The Donut class is intended to be an abstract and simplified representation of a

ID: 3857115 • Letter: T

Question

The Donut class is intended to be an abstract and simplified representation of a yummy edible donut. Name of the donut Type of donut Price of the donut Donut name must not be empty (Default: "Classic") Type of donut can only be one of the following: "Plain, " "Filled, " or "Glazed" (Default: "Plain") Public Getter and Private Setter for name, type, and price - enforce invariants A constructor that takes in as argument the name and type of the donut (enforce invariants) Determine the price of the donut based on the type: $0.99 for plain $1.29 for glazed $1.49 for filled A toString() method that returns the name, type, and price of the donut. An equals() method that returns true if it's the same name and type (regardless of price). The DonutBox class is intended to be an abstract and simplified representation of a box of donuts. Among other things, this object should be able to list the price of the donuts. Donuts (Donut[])-an array of donuts Count - number of donuts in the box A box can have at most a dozen donuts Public getter ONLY for count public void addDonut (Donut order) {} public double getPrice(){} Returns the total the total price (before tax) of the donuts in the box, with applicable discount: Under 6 donuts, no discount 6 to 12 donuts, 10% discount 12 donuts exactly. 20% discount public String toString(){} - returns a String containing all the donuts in the box An enum for box type (Small, Medium, Large) A public method that returns the size of the box as an enum constant. Small box fits exactly one donut, medium fits up to six donuts, large fits up to 12.

Explanation / Answer


import java.util.Objects;

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author Sam
*/
public abstract class DonutBox {
    public static enum boxType {
        SMALL,
        MEDIUM,
        LARGE
    }
  
    Donut donuts[];
    int count;

    public int getCount() {
        return count;
    }
  
    public void addDonut(Donut order){
        donuts[count++] = order;
    }
  
    double totalPrice(){
        double price = 0;
        for(Donut d:donuts)
            price = price + d.getPrice();
        if (count == 12)
            price = price * 0.8;
        else if (count >= 6)
            price = price*0.9;
        return price;
    }
  
    public boxType boxSize(){
        if (count == 1)
            return boxType.SMALL;
        else if (count <= 6)
            return boxType.MEDIUM;
        else
            return boxType.LARGE;
    }
}

class Donut {
    private String name;
    private String type;
    private double price;

    public Donut(String name, String type) {
        this.name = name;
        this.type = type;
        if (type.equalsIgnoreCase("Plain"))
            price = 0.99;
        if (type.equalsIgnoreCase("Glazed"))
            price = 1.29;
        if (type.equalsIgnoreCase("Filled"))
            price = 1.49;
    }

    public Donut() {
        name = "Classic";
        type = "Plain";
        price = 0.99;
    }

    @Override
    public String toString() {
        return "Donut{" + "name=" + name + ", type=" + type + ", price=" + price + '}';
    }

    @Override
    public int hashCode() {
        int hash = 7;
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Donut other = (Donut) obj;
        if (!Objects.equals(this.name, other.name)) {
            return false;
        }
        if (!Objects.equals(this.type, other.type)) {
            return false;
        }
        return true;
    }

    public String getName() {
        return name;
    }

    public String getType() {
        return type;
    }

    public double getPrice() {
        return price;
    }

    private void setName(String name) {
        this.name = name;
    }

    private void setType(String type) {
        this.type = type;
    }

    private void setPrice(double price) {
        this.price = price;
    }
  
}

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