FILE of specialityCoffee: public class SpecialityCoffee extends Coffee { // Additional member variable private String flavor; public SpecialityCoffee() { // Calls super-constructor to create default

Answered step by step
Verified Expert Solution
Question
39 users unlocked this solution today!

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

FILE of specialityCoffee:

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 to 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; }

}

FILE OF RUNNER CODE:

import java.util.Scanner; public class runner_Coffee {

private static SpecialityCoffee c;

public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.println("Choose constructor to test: 1 - SpecialityCoffee() 2 - SpecialityCoffee(String size, String type, String flavor) 3 - SpecialityCoffee(String size, boolean isSkinny, int shots, String type, String flavor)"); int which = scan.nextInt(); if (which == 1) { c = new SpecialityCoffee(); } else if (which == 2 || which == 3) { scan.nextLine(); System.out.println("Size?"); String sz = scan.nextLine(); System.out.println("Type?"); String tp = scan.nextLine(); System.out.println("Flavor?"); String fl = scan.nextLine(); if (which == 3) { boolean iS = false; System.out.println("Is Skinny (y)?"); String sk = scan.nextLine().toLowerCase(); if(sk.equals("y")||sk.equals("yes")||sk.equals("t")||sk.equals("true")); iS = true; System.out.println("Shots?"); int sh = scan.nextInt(); c = new SpecialityCoffee(sz, iS, sh, tp, fl); } else c = new SpecialityCoffee(sz, tp, fl); } if(c != null) { System.out.println(c); int p = c.getPrice(); System.out.println("$"+p/100 + "."+ (p%100)/10 + p%10); } } }

FILE OF COFFEE:

public class Coffee { private String size; private boolean isSkinny; private int shots; private String type;

public Coffee() { this("small", false, 1, "latte"); }

public Coffee(String size, boolean isSkinny, int shots, String type) { this.size = size; this.isSkinny = isSkinny; this.shots = shots; this.type = type; }

public String toString() { String s = size; if (isSkinny) s += " skinny"; return s + " " + shots + "-shot " + type; }

public String getSize() { return size; }

public int getPrice() { int price; if (size.equals("extra large")) price = 470; else if (size.equals("large")) price = 440; else if (size.equals("medium")) price = 360; else price = 330;

price += shots*30; return price; } }

Instructions In this exercise you will return to your speciality Coffee class which you created for the last coding activity (a sample solution to this exercise is already provided but you may paste your own code from the previous lesson if you prefer). 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. You should test your code by running the main method of the runner class. Do not add a main method to your SpecialityCoffee.java file or your code will not be scored correctly. STATUS Files SAVE NOT SUBMITTED SUBMIT IN 1 public class SpecialityCoffee extends Coffee 2- { SpecialityCoffee.java // Additional member variable private String flavor; runner Coffee.java Coffee.java 3 4 5 6 7 8 - 9 10 11 12 13 14 15 - 16 17 18 19 20 public SpecialityCoffee { 1/ Calls super-constructor to create default coffee then sets flavor SuperO; 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); ); is = true; System.out.println("Shots?"); int sh = scan.nextInt(); C = new SpecialityCoffee (sz, is, sh, tp. fl); 31 32 33 34 35 37 38 else C = new SpecialityCoffee (sz, tp, fl); Files STATUS NOT SUBMITTED SAVE SUBMIT SpecialityCoffee.java runner Coffee.java Coffee.java public Coffee (String size, boolean isskinny, int shots, sying type) 1 public class Coffee 2-1 3 private String size; 4 private boolean isSkinny: 5 private int shots; 6 private String type; 2 8 public Coffee () { 10 this("small", false, 1, "latte"); 11 3 12 13 14 { 15 this.size = size; 16 this.isSkinny = isSkinny; 17 this.shots = shots; 18 this.type = type; 19 + 20 21 public String toString() 22 { 23 Strings = size; 24 if (isskinny) 25 5 += " skinny"; 26 return s + " " + shots + "-shot + type; 27 } 28 29 public String getSize() 30 { 31 return size; 32 } 33 34 public int getPrice) 35 - { 36 int price; 37 if (size.equals("extra large")) 38 price = 470; 39 else if (size.equals("large")) 40 price = 440; 41 else if (size.equals("medium"))

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Link Copied!

Step: 1

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

100% Satisfaction Guaranteed-or Get a Refund!

Step: 2Unlock detailed examples and clear explanations to master concepts

blur-text-image_2

Step: 3Unlock to practice, ask and learn with real-world examples

blur-text-image_3

See step-by-step solutions with expert insights and AI powered tools for academic success

  • tick Icon Access 30 Million+ textbook solutions.
  • tick Icon Ask unlimited questions from AI Tutors.
  • tick Icon Order free textbooks.
  • tick Icon 100% Satisfaction Guaranteed-or Get a Refund!

Claim Your Hoodie Now!

Recommended Textbook for

25 Vba Macros For Data Analysis In Microsoft Excel

Authors: Klemens Nguyen

1st Edition

B0CNSXYMTC, 979-8868455629

flashcard-anime

Study Smart with AI Flashcards

Access a vast library of flashcards, create your own, and experience a game-changing transformation in how you learn and retain knowledge

Explore Flashcards

Students Have Also Explored These Related Databases Questions!

Q:

Write short notes on Interviews.

Answered: 3 weeks ago