Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Create an entity class Cake and carry out the following: a. Encapsulate information about the following: name and calories (ensure you use the principles
Create an entity class Cake and carry out the following: a. Encapsulate information about the following: name and calories (ensure you use the principles of encapsulation and information hiding). b. Define 2 overloaded constructors, one with no parameters, the other with parameters corresponding to the above fields; the constructors must ensure that calories can only take values above 0; otherwise, the constructor should throw an appropriate runtime exception. C. Define setter methods corresponding to each field and, in a similar manner to the constructor, they should ensure the arguments passed satisfy the above conditions. d. Define getter methods corresponding to each field. e. Finally, override the method toString so that it returns the string representation of a cake's details.
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