Question

In: Physics

In this exercise you will return to your SpecialityCoffee class which you created for the last...

In this exercise you will return to your SpecialityCoffee class which you created for the last coding activity (a sample solution to this exercise will be shown below the entire question if you do not have yours). This time you will override the Coffee method getPrice which returns the price in cents for a given coffee.

The SpecialityCoffee method getPrice should return the price given by the Coffee method for that object, plus an extra charge for the flavored syrup. This extra charge is 70 cents if the coffee size is "large" or "extra large", and 50 cents otherwise.

Remember, to submit a solution you should paste your entire SpecialityCoffee class into the coderunner, which uses its own version of the Coffee class.

sample code from the last coding activity
public class SpecialityCoffee extends Coffee{
  
  // Additional member variable
  private String flavor;
  
  public SpecialityCoffee(){
    // Calls super-constructor to create default coffee then sets flavor
    super();
    flavor = "vanilla";
  }
  
  public SpecialityCoffee(String size, String type, String flavor){
    
    // Calls constructor below with a mix of parameters and default values
    this(size, false, 1, type, flavor);
  }
  
  public SpecialityCoffee(String size, boolean isSkinny, int shots, String type, String flavor){
    
    // Calls super-constructor tos set first 4 variables then sets flavor
    super(size, isSkinny, shots, type);
    this.flavor = flavor;
  }
  
  public String toString(){
    // Calls Coffee toString and appends flavor to end
    return super.toString() + " with " + flavor;
  }
}

Solutions

Expert Solution

public class SpecialityCoffee extends Coffee{
// Additional member variable
private String flavor;
public SpecialityCoffee(){
// Calls super-constructor to create default coffee then sets flavor
super();
flavor = "vanilla";
}
  
public SpecialityCoffee(String size, String type, String flavor){
// Calls constructor below with a mix of parameters and default values
this(size, false, 1, type, flavor);
}

public SpecialityCoffee(String size, boolean isSkinny, int shots, String type, String flavor){
// Calls super-constructor tos set first 4 variables then sets flavor
super(size, isSkinny, shots, type);
this.flavor = flavor;
}
public String toString(){
// Calls Coffee toString and appends flavor to end
return super.toString() + " with " + flavor;
}

public Float getPrice(){
this.price = this.getPrice();
if(this.size == "large"|| this.size == "extra large"){
this.price = this.price + 0.7;
}
else{
this.price + 0.5;
}

return this.price;
}
}

the last class is the getPrice method, overriding the getPrice method of the coffee class to return coffee price with premium according to the coffee size


Related Solutions

Prompt: This exercise uses your programming environment to enhance the Web site you created last week...
Prompt: This exercise uses your programming environment to enhance the Web site you created last week with additional functionality to include images, tables and a Form using Python flask. Specifically, you will add two (2) additional routes allowing a user to register and login to a web site. Additional security considerations include other routes (beyond the register route) will not be accessible until a successful login has occurred. In addition to the requirements list above the following functionality should be...
In the previous lab you created a Car class and a Dealership class. Now, in this...
In the previous lab you created a Car class and a Dealership class. Now, in this activity change the design of the Dealership class, in which the list of the cars inside a dealership will be stored in an ArrayList. Then, provide required getter and setter methods to keep the records of all its cars. In your tester class, test your class and also printout the list of all cars of a given dealership object. // Java program import java.util.ArrayList;...
You were the top student in your physiology class last semester. For this reason, your professor...
You were the top student in your physiology class last semester. For this reason, your professor has asked that you prepare some lectures for her physiology class this semester. Specifically, she would like you to discuss the similarities and differences between the cardiovascular and respiratory systems, in terms of pressure gradients and fluid flow. A. Explain how you will describe the role of the following structures: the pump and the tubes. B. Explain how you will describe the importance of...
1) You were the top student in your physiology class last semester. For this reason, your...
1) You were the top student in your physiology class last semester. For this reason, your professor has asked that you prepare some lectures for her physiology class this semester. Specifically, she would like you to discuss the similarities and differences between the cardiovascular and respiratory systems, in terms of pressure gradients and fluid flow. Explain how will you describe the role of the following structures: the pump and the tubes. 2) Julia is breathing 14 times per minute, with...
1) You were the top student in your physiology class last semester. For this reason, your...
1) You were the top student in your physiology class last semester. For this reason, your professor has asked that you prepare some lectures for her physiology class this semester. Specifically, she would like you to discuss the similarities and differences between the cardiovascular and respiratory systems, in terms of pressure gradients and fluid flow. Explain how will you describe the role of the following structures: the pump and the tubes. 2) List, compare, and contrast the locations and stimuli...
You earned a nominal rate of return equal to 10.50% on your investments last year. The...
You earned a nominal rate of return equal to 10.50% on your investments last year. The annual inflation rate was 2.60%. a. What was your approximate real rate of return? (Round your answer to 2 decimal places.) Approximate real rate of return % b. What was your exact real rate of return? (Round your answer to 2 decimal places.) Real rate of return %
public class AllEqual { // You must define the allEqual method, which will return // true...
public class AllEqual { // You must define the allEqual method, which will return // true if either: // 1.) The given array contains fewer than two elements, or... // 2.) All elements of the array are equal to each other. // As a hint, you only need to compare the first element // to all subsequent elements for this check. // // TODO - define your code below this comment // // DO NOT MODIFY parseStrings! public static int[]...
Exercise 15-1 Analyze the last poor decision made by a group of which you were a...
Exercise 15-1 Analyze the last poor decision made by a group of which you were a member. what do you think contributed to the group's poor decision? Did the group think of alternative possibilities? Did the group move too quickly through any of the development stages? If yes, did this cause a lack of cooperation or poor communication?  
In this exercise, you created master data, and you entered transactions corresponding to business processes. In...
In this exercise, you created master data, and you entered transactions corresponding to business processes. In many businesses, those persons who create master data are not allowed to create business process transactions. Similarly, those who create business process transactions are not allowed to create master data. Why would organizations establish these restrictions?
Using the class Date that you defined in Exercise O3, write the definition of the class...
Using the class Date that you defined in Exercise O3, write the definition of the class named Employee with the following private instance variables: first name               -           class string last name                -           class string ID number             -           integer (the default ID number is 999999) birth day                -           class Date date hired               -           class Date base pay                 -           double precision (the default base pay is $0.00) The default constructor initializes the first name to “john”, the last name to “Doe”, and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT