ROGRAM  For this program, you are tasked to implement the Beverage class which has the following private properties: name - a string value volume - this is an integer number which represents its current remaining volume in mL isChilled - this is a boolean field which is set to true if the drink is chilled   It should have the following methods: isEmpty() - returns true if the volume is already 0 {toString() - returns the details of the object in the following format: {name} ({volume}mL) {"is still chilled" | "is not chilled anymore"}.Example returned strings: Beer (249mL) is still chilled Water (500mL) is not chilled

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

JAVA PROGRAM 

For this program, you are tasked to implement the Beverage class which has the following private properties:

  • name - a string value
  • volume - this is an integer number which represents its current remaining volume in mL
  • isChilled - this is a boolean field which is set to true if the drink is chilled

 

It should have the following methods:

  • isEmpty() - returns true if the volume is already 0
  • {toString() - returns the details of the object in the following format: {name} ({volume}mL) {"is still chilled" | "is not chilled anymore"}.Example returned strings:
    • Beer (249mL) is still chilled
    • Water (500mL) is not chilled anymore
  • A constructor method with the following signature: public Beverage(name, volume, isChilled)
  • Getter methods for all the 3 properties.

 

Then, create two final subclasses that inherit from this Beverage class. The first one is the Water class which has the additional private property, type, which is a String and can only be either "Purified", "Regular", or "Distilled". It should have the following methods:

  • 1st constructor: public Water(volume, isChilled, type) - when calling its parent class' constructor, pass "Water" as the name
  • 2nd constructor: public Water(volume, isChilled) - the type will be set to "Regular" and similar to the 1st constructor, pass "Water" as the name to its parent class' constructor
  • A getter for its type

 

The second subclass to be created is the Beer class which has the additional private property, alcoholicContent, which is the percentage of alcoholic content in the beer in percentage (0.01 to 1.00). It should have 1 constructor only which the following signature: public Beer(volume, isChilled, alcoholicContent), and you need to pass "Beer" as the name for its parent class' constructor call. There should also be a getter for the alcoholicContent. Additionally, implement the following methods:

  • String getType()
    • this returns "Flavored" if the alcoholic content is below 0.03, "Regular" if the alcoholic content is 0.03 and above but below 0.06, and "Strong" if it's 0.06 and above
  • String toString()
    • calls its parent class' toString() method and appends in the end its alcoholic percentage with 1 decimal place. For example:
      • Beer (249mL) is still chilled (6.0% alcoholic content)

 

For this problem, you are also in charge in creating the main. In the main, you will ask the user for the following details:

  • Type (1 for Water, 2 for Beer)
  • Volume
  • Is Chilled ('Y' for yes while 'N' for no)
  • If the type is water, ask the user if to input the type. If the type is beer, ask the user to input the alcoholic content.

 

Example user prompts:

Select type (1 - Water, 2 - Beer): 1

Enter volume: 249

Is chilled (Y - yes, N - no): Y

Type: Distilled

 

Select type (1 - Water, 2 - Beer): 2

Enter volume: 500

Is chilled (Y - yes, N - no): N

Alcoholic content: 0.04

 

Then, after asking for these prompts from the user, create the object using the appropriate class (i.e. if the type inputted is 1, then create a Water object. If the type inputted is 2, then create a Beer object). Finally, call the built-in Tester.test() method and pass this object you just created.

Expert Solution
steps

Step by step

Solved in 5 steps with 2 images

Blurred answer
Knowledge Booster
Concept of pointer parameter
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY