Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Beverage Class 4 instance attributes: name, type (valid values are juice, soda, flavored water, sports, etc.), ounces (a number with no decimals) and isCarbonated, which

Beverage Class

4 instance attributes: name, type (valid values are "juice", "soda", "flavored water", "sports", etc.), ounces (a number with no decimals) and isCarbonated, which is true or false.

2 Constructors:

A 4-parameter constructor

A 3-parameter constructor that passes in ounces, name and type and defaults the isCarbonated attribute to false.

Write getters and setters for all 4 instance attributes.

The class has 2 custom methods:

public boolean ouncesEndsWith6() this method determines if the number of ounces ends with the number 6. For example, 96 returns a true, 12 returns a false, 116 returns a true. HINT: the modulo operator helps here!!!

public boolean typeBeginsWith(String str) this method determines if the type begins with a specific set of characters, case sensitive, that are passed as a parameter. For example: The type "soda" returns true for a str of "so", but it returns false for a str of "So" or "ev".

Write a readable and neat toString(). Output will have all 4 instance attributes and it will invoke the endsWith6 method. Label your output appropriately.

BeverageTester

Create at least 5 beverage objects and place them in an array list. Ensure that you use both constructors and that your data will test your methods well. Output all of your beverages in your array list using one line of Java code.

Write an enhanced for loop that determines the beverage that contains the maximum number of ounces. Print out the beverage name and the number of ounces; label your output.

Using the two last beverages you created, test your typeBeginsWith method. Label your output so it is easily identified.

Write a loop that averages the ounces in all of your beverages. This average will contain a decimal. Label your output so that the average is easily identified.

image text in transcribed

Je currently sell Fruit and Pastry at our store. Now we are going to add a type of item-Beverage! everage Class 1. 4 instance attributes: name, type (valid values are "juice", "soda", "flavored water", "sports", etc.), ounces (a number with no decimals) and isCarbonated, which is true or false. 2. 2 Constructors: a. A 4-parameter constructor b. A 3-parameter constructor that passes in ounces, name and type and defaults the isCarbonated attribute to false. 3. Write getters and setters for all 4 instance attributes. 4. The class has 2 custom methods: a. public boolean ouncesEndswith 6() - this method determines if the number of ounces ends with the number 6 . For example, 96 returns a true, 12 returns a false, 116 returns a true. HINT: the modulo operator helps here!!! b. public boolean typeBeginswith (String str) - this method determines if the type begins with a specific set of characters, case sensitive, that are passed as a parameter. For example: The type "soda" returns true for a str of "so", but it returns false for a str of "So" or "ev". 5. Write a readable and neat tostring () . Output will have all 4 instance attributes and it will invoke the endsWi th 6 method. Label your output appropriately. everagetester 1. Create at least 5 beverage objects and place them in an array list. Ensure that you use both constructors and that your data will test your methods well. Output all of your beverages in your array list using one line of Java code. 2. Write an enhanced for loop that determines the beverage that contains the maximum number of ounces. Print out the beverage name and the number of ounces; label your output. 3. Using the two last beverages you created, test your typeBeginsWith method. Label your output so it is easily identified. 4. Write a loop that averages the ounces in all of your beverages. This average will contain a decimal. Label your output so that the average is easily identified. ubmit your 2 .java files, Beverage. java and BeverageTester.java

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

Upgrading Oracle Databases Oracle Database New Features

Authors: Charles Kim, Gary Gordhamer, Sean Scott

1st Edition

B0BL12WFP6, 979-8359657501

More Books

Students also viewed these Databases questions