Question: Write a full Java program which contains two classes. The class CakeShop should contain the main method. The class Cake should use appropriate data encapsulation

Write a full Java program which contains two classes.

The class CakeShop should contain the main method.

The class Cake should use appropriate data encapsulation practices. It should have the following attributes:

(1) a String called flavor

(2) a double called price

(3) a boolean called isSold that should be set to false as default

(4) a static variable of type int called numberOfCakesSold to keep track of the number of cakes sold that is initialized to 0

(5) a static variable of type double called accountBalance initialized to 0.0

The Cake class should have (1) a constructor that allows you to create a Cake object by setting the attributes (2) a second constructor that assigns default values by invoking the constructor from (1).

The Cake class should have the following methods:

(1) Relevant get and set methods

(2) a method called sell should set isSold for the object to true and increase accountBalance by price and should keep track of number of cakes sold.

In the main method, create two Cake objects - one where you assign values and another where you use default values. Sell both cakes. Print your results. Display accountBalance and numberOfCakesSold.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!