Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

File of runner coffee: import java.util.Scanner; public class runner_Coffee { private static SpecialityCoffee c; public static void main(String[] args) { Scanner scan = new Scanner(System.in);

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

File of runner coffee:

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) { System.out.println("Is Skinny (y)?"); String sk = scan.nextLine().toLowerCase(); boolean iS = (sk.equals("y")||sk.equals("yes")||sk.equals("t")||sk.equals("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); } } }

FILE OF COFFEE JAVA:

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 For this coding activity you will need to write a subclass of the coffee class which you can view in the Coffee.java file. This class has the following attributes: size (String), isskinny (boolean), shots (int) and type (String). You will not need to edit this class for the exercise. You will write a Specialitycoffee class which extends the Coffee class, and has the additional attribute flavor (String). You will write 3 constructors for your class: the first will be a default constructor with no parameters which creates a small non-skinny, single-shot latte with vanilla. The second will take three parameters: size, type and flavor and set the relevant attributes to these values, and all other values to default. The final constructor has 5 parameters representing each of the attributes of a Specialitycoffee. When you have written the constructors, you should add a toString method which prints the specialityCoffee as though it was a coffee object, but adds "with" and the flavor to the end of this String. The table below summarizes the state of the object created by calls to the three different constructors, along with what would be printed by the toString method in each case. new SpecialityCoffee ("large", "mocha", new Speciality Coffee () new SpecialityCoffee ("medium", true, 2, "cappuccino", "gingerbread") "caramel") size "small" "large" "medium" isSkinny false false true shots 1 1 2 type "latte" "mocha" flavor "vanilla" "caramel" "cappuccino" "gingerbread" "medium skinny 2-shot cappuccino with gingerbread" toString "small 1-shot latte with vanilla" "large 1-shot mocha with caramel" 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. Files STATUS NOT SUBMITTED SAVE SUBMIT 1 Speciality Coffee.java runner Coffee.java Coffee.java I Drevious Files NOT SUBMITTED SAVE SUBMIT IN Speciality Coffee.java runner Coffee.java Coffee.java 1 - import java.util.Scanner; 2 public class runner_Coffee 3- { 4 5 private static SpecialityCoffee c; 6 7 public static void main(String[] args) 8- { 9 Scanner scan = new Scanner(System.in); 1e System.out.println("Choose constructor to test: 1 - SpecialityCoffee() 2 Speciality Coffee (String size, String type, String flavor) 3 SpecialityCoffee(String size, boolean isskinny, int shots, String type, String flavor)"); 11 int which scan.nextInt(); 12 if (which = 1) 13 - { 14 C = new SpecialityCoffee(); 15 } 16 else if (which == 2 11 which == 3) 17 - { 18 scan.nextLine(); 19 System.out.println("Size?"); 20 String sz = scan.nextLine(); 21 System.out.println("Type?"); 22 String tp = scan.nextLine(); 23 System.out.println("Flavor?"); 24 String fl = scan.nextLine(); 25 if (which == 3) 26 - { 27 System.out.println("Is Skinny (y)?"); 28 String sk = scan.nextLine().toLowerCase(); 29 boolean is = (sk.equals("")llsk.equals("yes") sk.equals("t"Isk .equals("true")); 30 System.out.println("Shots?"); 31 int sh = scan.nextInt(); 32 c = new SpecialityCoffee (sz, is, sh, tp, fl); 33 34 else 35 - { 36 = new SpecialityCoffee(sz, tp, fl); 37 > 38 Files STATUS NOT SUBMITTED SAVE SUBMIT Speciality Coffee.java runner Coffee.java Coffee.java 1 public class Coffee 2- { 3 private String size; 4 private boolean isSkinny; 5 private int shots; 6 private String type; 7 8 public Coffee() 9- { 10 this("small", false, 1, "latte"); 11 3 12 13 public Coffee (String size, boolean isskinny, int shots, String type) 14 - { 15 this.size = size; 16 this.isSkinny = isSkinny; 17 this. Shots = shots, 18 this.type = type; 19 20 21 public String toString() { 23 String s = size; 24 if (isskinny) 25 s += 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")) 49 price = 440; 41 else if (size.equals("medium") 42 price = 360; 22

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

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

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Experts Guide To SQL

Authors: Frank Lusardi

1st Edition

0070390029, 978-0070390027

More Books

Students also viewed these Databases questions

Question

What is the purpose of a statement of cash flows?

Answered: 1 week ago

Question

Lo6 Identify several management development methods.

Answered: 1 week ago

Question

LO4 List options for development needs analyses.

Answered: 1 week ago