Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is my code --------------------- enum Flavor { Original, Diet, Zero, Cherry } // create Coke class class Coke { // private members boolean isDetected;

This is my code

---------------------

 enum Flavor { Original, Diet, Zero, Cherry } // create Coke class class Coke { // private members boolean isDetected; Flavor flavor; String blendName; String brandName; // constructors public Coke(String blend, String brand, Flavor fl, boolean isDetect) { isDetected = isDetect; blendName = blend; brandName = brand; flavor = fl; } public Coke(String blend, String brand, Flavor fl) { isDetected = false; blendName = blend; brandName = brand; flavor = fl; } public Coke(String blend, String brand) { isDetected = false; blendName = blend; brandName = brand; flavor = Flavor.Original; } // required methods public boolean is_detected() { return isDetected; } public Flavor getFlavor() { return flavor; } public String getBrandName() { return brandName; } public String getBlendName() { return blendName; } public boolean examine() { if (isDetected == true) { return false; } else { isDetected = true; return true; } } // here we are overridding toString method public String toString () { if(isDetected == false) return String.format("Brand: " + brandName + " " + "Blend: " + blendName + " " + "Flavor Type: " + flavor + " " + "Undetected"); else return String.format("Brand: " + brandName + " " + "Blend: " + blendName + " " + "Flavor Type: " + flavor + " " + "Detected"); } } public class Main { public static void main(String[] args) { // create Coke object Coke ob = new Coke("Happy Coke", "Happy 7911", Flavor.Zero); // use of overridden method toString System.out.println(ob); } }

---------------------------------------

Hello, my code is above. and I meet a problem. For main part "public class Main" at the bottom, I want to change the input ""Happy Coke", "Happy 7911", Flavor.Zero" to ("Happy Coke", "Happy 7911", Coke.Flavor.Zero) but it will show errors, what should I do to make it work, no need to learn about what's the subject, just help modify the code, Thanks.

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

Step: 3

blur-text-image

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

DB2 11 The Ultimate Database For Cloud Analytics And Mobile

Authors: John Campbell, Chris Crone, Gareth Jones, Surekha Parekh, Jay Yothers

1st Edition

1583474013, 978-1583474013

More Books

Students also viewed these Databases questions