Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2) (a) Create an exception class called IceCreamConeException, whose constructor accepts a String for a message to be passed to the parent of the class

2) (a) Create an exception class called IceCreamConeException, whose constructor accepts a String for a message to be passed to the parent of the class so it can be used in a getMessage() call for display. The received message by the IceCreamConeException class constructor should indicate the reason for the thrown exception (e.g, Non-acceptable flavor, or number of scoops) and the value causing the exception. (b) Create a class called IceCreamCone which has two instance variables, Flavor as a String and Scoops as an integer, and a constant String array of flavor choices, called FLAVORS. Allow at least four flavors of your choice. The IceCreamCone class has a constructor that receives two parameters to initialize the Flavor and Scoops variables. The constructor uses two methods for setting the instance variables: setFlavor() and setScoops(). The setFlavor() method throws an IceCreamConeException, if the users entry does not match a valid flavor from the list of flavor choices. The setScoops() method throws an IceCreamConeException when the scoop quantity exceeds four. Also, the IceCreamCone class includes a getter method for the FLAVORS list, and a toString method. (c) Write a client class that builds a list of IceCreamCone objects using an array of maximum size of 10. The client allows a user to enter from the keyboard values for an ice cream flavor and number of scoops. The client class catches and handles the exception if it is thrown due to creating unacceptable IceCreamCone object that does not satisfy the IceCreamCone conditions. The exception is handled by printing an appropriate message. Display an appropriate message when an IceCreamCone object is created successfully and when one is not. At the end, display the list of accepted IceCreamCone items. Show examples of IceCreamCone objects with valid and invalid values.

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

Information Modeling And Relational Databases

Authors: Terry Halpin, Tony Morgan

2nd Edition

0123735688, 978-0123735683

More Books

Students also viewed these Databases questions

Question

What are five basic components of an accounting system?

Answered: 1 week ago

Question

(1 point) Calculate 3 sin x cos x dx.

Answered: 1 week ago