Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In this exercise, we create an abstract Beverage class. We then create two concrete classes, IceWater and Hot Tea. These subclasses differ in their implementation
In this exercise, we create an abstract Beverage class. We then create two concrete classes, IceWater and Hot Tea. These subclasses differ in their implementation of the drink() method, which is why in the Beverage class, the drink() method is abstract. Each class contains at least one error. There are five total errors across all four classes. Please identify all errors and explain what must be done to correct each error. Your response must be in detailed, complete sentences. Important: Each class is contained in a separate file. Below is the source code for all four files: package packagel; public abstract class Beverage { private int ounces; private double price; Beverage (int ounces, double price) { this.ounces = ounces; this.price = price; } public int getOunces () { return ounces; } public double getPrice () { return price; } public abstract String drink(); } package package2; + import package1.*; public class HotTea implements Beverage { public HotTea(int ounces, double price) { super (ounces, price); } public String drink() { return "This tea is hot and soothing."; package packagel; public class IceWater implements Beverage { I public IceWater (int ounces, double price) { super (ounces, price); public String drink() { return "This ice water is cool and refreshing." } } package package2; static import java.lang. System.out; public class TestBeverage { public static void main(String[] myListofargs) { IceWater drinki = new IceWater (16, 1.00); Hot Tea drink2 = new Hot Tea (10, 2.99); out.print("The water is " + drinki.getOunces () + " ounces "); out.println("and costs $" + drinki.getPrice() + "."); out.println(drink1.drink()); out.print("The tea is " + drink2.getOunces() + " ounces "); out.println("and costs $" + drink2.getPrice () + " "); out.println(drink2.drink()); 1 }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started