Clara is a perfectionist and always tries to improve every aspect of her job. As a cake maker, she is not entirely satisfied with the cake she baked for Problem 1. This time she wants to add candles to make it look more interesting. The initial configuration of Clara’s world is shown in Figure 1. Similar to problem 1, she must request the width and height of the cake from the user. Once the width and height are entered correctly, Clara must bake the cake as before, but then she also has to add a number of candles so that the entire cake is covered with them as shown in Figure 2. The candles on the cake are 3 cells tall and must be located with 1 cell interval between them. The number of candles must be automatically calculated depending on the width of the cake. Note, that the range of acceptable height for the cake base will change because now not only the base, but also the candles must fit within Clara’s world. So you must modify your validation accordingly.

University/Course: WSU

Uploaded: October 27, 2024

Files: 1

✓ Solution:

class MyClara extends Clara { 
/**
     * In the ‘run()’ method you can write your program for Clara 
     */
void run() {
// Define the width and height of the cake
int cakeWidth = readInt(“Enter the width of the cake:”);
int cakeHeight = readInt(“Enter the height of the cake:”);
// Building the cake layer by layer
while (cakeHeight > 0) {
// Build the first row of the cake
for (int i = 0; i < cakeWidth; i++) {
                placeLeaf();
                move();
            }
// Move to the next row (from the left side)
            turnLeftToStartNextLayer();
            cakeHeight–;
// Build the second row of the cake
for (int i = 0; i < cakeWidth; i++) {
                placeLeaf();
                move();
            }
// Move to the next row (from the right side)
            turnRightToStartNextLayer();
            cakeHeight–;
        }
// After building the cake, place candles on top
for (int i = 0; i < 5; i++) {
            placeCandle();  // Position and place a candle on the cake
        }
    }

🔒 Whatsapp us for the full file.