I am not understanding the question below at all can someone please guide me in the right direction. I do understand what a Boolean is but i am unclear on how to change the code as directed below.

Thank you for your time.

Change the java code below so that frostCake returns a boolean value:


import java.awt.*;



public class Cake {



         int topLocation;

         int leftLocation;

         String cakeFlavor;



    public Cake(int top, int left) {

        topLocation = top;

        leftLocation = left;

     }        



    public Cake(int top, int left, String flavor) {

        topLocation = top;

        leftLocation = left;

	cakeFlavor = flavor;

    }       





    public void frostCake(Color myColor, Graphics g) {

        g.setColor(myColor);

        g.fillRect(leftLocation, topLocation, 50, 50);



        g.setColor(Color.black);

        g.drawString("I am a" + cakeFlavor + "Cake.", leftLocation + 50, topLocation + 50);

    }



    public static String combine(String firstString, String secondString){



         String combinedString = firstString + secondString;

         return combinedString;



    }

}

For a method to return a type other than void, you need specify the type you wish to return in the construction of the method.

public void frostCake

This method declaration tells you 3 things.
1.the modifier (public)
2.the return type...in this case the return type is void
3. The methods name

Which means, in order to return a value that is not void, i.e. int,String,double,boolean, you set the return type to whichever you want to return, and then return some value with that type

public boolean frostCake(Color myColor, Graphics g) {
g.setColor(myColor);
g.fillRect(leftLocation, topLocation, 50, 50);
g.setColor(Color.black); 
g.drawString("I am a" + cakeFlavor + "Cake.", leftLocation + 50, topLocation + 50);


//Then you need to specify what you want to return

return true; // or you could create some boolean variable and return that
}

Thank you for your help ! ;D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.