Question: Java code working is required. Create an entity class Cake and carry out the following: a. Encapsulate information about the following: name and calories (ensure

Java code working is required.


attachment1.png


 

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. 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. C.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

public class Cake private St... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!