Question

In: Computer Science

Language: Java Crust : A small pizza costs $5.99, a medium is $7.99, and a large...

Language: Java

Crust :

A small pizza costs $5.99, a medium is $7.99, and a large is $9.99.

A handtossed crust is an additional $0.50, and a deep dish pan crust is an additional $1.00.

Do a CrustSize enum [S(5.99), M(7.99), and L(9.99)] and a CrustType enum [THIN(0.00), HAND(0.50), and PAN(1.00)].

Place your enums in CrustEnum.java.

Both enums should have cost methods.

Do a Crust class with a constructor that accepts and sets the crust size and type, and provide a crustCost method.

Do a toString method to report the state of the crust.

Write getCrust (returns "THIN", "HAND", or "PAN") and getSize (returns a char 'S', 'M', or 'L').

I have most of it already, I just need help with the Crust class, aka the crustCost, toString, and getCrust.

There is a toString method, though I dont know if its right, as well as a crustCost.

If you need to delete something because it is wrong, feel free.

CrustEnum.java:

public enum CrustSize{
   S(5.99),
   M(7.99),
   L(9.99);

   private double cost;
  
   private CrustSize(double cost){
       this.cost = cost;
   }
  
   public double getCost(){
       return this.cost;
  
}

public enum CrustType{
   THIN(0.00),
   HAND(0.50),
   PAN(1.00);
  
   private double cost;
  
   CrustType(double cost){
       this.cost = cost;
      
   }
   public double getCost(){
       return this.cost;
   }
}

private CrustSize size;
private CrustType type;

public CrustEnum(String size, String type){
   this.size = CrustSize.valueOf(size);
   this.type = CrustType.valueOf(type);
}

public double CrustCost(){
   return (size.getCost() + type.getCost());
}
}

public class Crust {
   private CrustEnum crust;
  
   public Crust(String size, String type){
       this.crust = new CrustEnum(size,type);
   }
  
   public String toString(){
       return "The crust is a " + this.size + " " + this.type + " pizza";
  
   public double crustCost(){
       return crust.crustCost();
   }
}

Solutions

Expert Solution

Code for the given question:

public class CrustEnum {

// Enum for crust size
public static enum CrustSize {
S(5.99), M(7.99), L(9.99);

// Attribute
private double cost;

/**
* Constructor
*
* @param size
*/
private CrustSize(double cost) {
this.cost = cost;
}

/**
* Gets the cost
*/
public double getCost() {
return this.cost;
}
}

// Enum for crust type
public static enum CrustType {
THIN(0.00), HAND(0.50), PAN(1.00);

// Attribute
private double cost;

/**
* Constructor
*
* @param size
*/
private CrustType(double cost) {
this.cost = cost;
}

/**
* Gets the cost
*/
public double getCost() {
return this.cost;
}
}

//Attibutes
private CrustSize size;
private CrustType type;

/**
* Constructor
* @param size
* @param type
*/
public CrustEnum(String size, String type) {
this.size = CrustSize.valueOf(size);
this.type = CrustType.valueOf(type);
}

/**
* Returns the crustcost
* @return
*/
public double crustCost() {
return (size.getCost() + type.getCost());
}
}

public class Crust {

//Attribute
private CrustEnum crust;

/**
* Constructor
* @param crustType
*/
public Crust(String size, String type) {
this.crust = new CrustEnum(size, type);
}

/**
* Returns the crustcost
* @return
*/
public double crustCost() {
return crust.crustCost();
}
}

We can create an object as

Crust crust = new Crust("M", "PAN");

So call crust.crustCost() method to get the total cost.


Related Solutions

. How do you determine if an effect is small, medium, or large?
. How do you determine if an effect is small, medium, or large?
Oysters are categorized for retail as small, medium, or large based on their volume. The grading...
Oysters are categorized for retail as small, medium, or large based on their volume. The grading process is slow and expensive when done by hand. A computer reconstruction of oyster volume based on image analysis would be desirable to speed the process. Engineers designed two programs estimating oyster volume, one based on two‑dimensional (2D) image processing and the other based on three‑dimensional (3D ) image processing. We want to know if either approach is a good predictor of actual oyster...
Oysters are categorized for retail as small, medium, or large based on their volume. The grading...
Oysters are categorized for retail as small, medium, or large based on their volume. The grading process is slow and expensive when done by hand. A computer reconstruction of oyster volume based on image analysis would be desirable to speed the process. Engineers designed two programs estimating oyster volume, one based on two‑dimensional (2 D) image processing and the other based on three‑dimensional (3 D) image processing. We want to know if either approach is a good predictor of actual...
Oysters are categorized for retail as small, medium, or large based on their volume. The grading...
Oysters are categorized for retail as small, medium, or large based on their volume. The grading process is slow and expensive when done by hand. A computer reconstruction of oyster volume based on image analysis would be desirable to speed the process. Engineers designed two programs estimating oyster volume, one based on two‑dimensional ( 2D ) image processing and the other based on three‑dimensional ( 3D ) image processing. We want to know if either approach is a good predictor...
Users may order one or more pizzas, where each pizza may be either: small, medium or...
Users may order one or more pizzas, where each pizza may be either: small, medium or large. Small pizzas cost $5, medium pizzas cost $8 and large pizzas cost $12. All pizzas come on a tomato base (for our pizza shop, this will be the only option), and will have the topping cheese by default, at no extra cost. Users may choose up to a maximum of four additional toppings (bringing the total to five) from the following list, where...
Three boxes, one large, one medium, and one small, contain white and red balls. The large...
Three boxes, one large, one medium, and one small, contain white and red balls. The large box, which is chosen half the time, contains fifteen white balls and eight red ones; the medium box, which is chosen three times out of ten, contains nine white balls and three red ones. The small box contains four white balls and five red ones. (a) On choosing two balls at random from the large box, what is the probability of (i) getting two...
Explain how the banking interest of large, medium and small businesses are represented on the Board...
Explain how the banking interest of large, medium and small businesses are represented on the Board of Directors of each reserve bank.
Question 2 A manager is trying to decide whether to build a small, medium, or large...
Question 2 A manager is trying to decide whether to build a small, medium, or large facility. Demand can be low, average, or high, with the estimated probabilities being 0.25, 0.40, and 0.35, respectively. A small facility is expected to earn an after-tax net present value of just $18,000 if demand is low. If demand is average, the small facility is expected to earn $75,000; it can be increased to medium size to earn a net present value of $60,000....
Evaluate the differences small, medium and large businesses make to the economy, applying relevant data and...
Evaluate the differences small, medium and large businesses make to the economy, applying relevant data and statistics.
Select a pizza restaurant and a sandwich shop. For the pizza restaurant look at the menu to determine how many sizes, crust types, and toppings are available. How many ..
Select a pizza restaurant and a sandwich shop. For the pizza restaurant look at the menu to determine how many sizes, crust types, and toppings are available. How many different pizza types are possible? For the sandwich shop determine how many breads, meats, veggies, cheeses, sauces, and condiments are available. How many different sandwich choices are possible?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT