In: Physics
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; } }
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