ok so I have to make that toggleCircusStatus() gives me the opposite of fromCircus

Write a public method called toggleCircusStatus that negates the value of the circusStatus variable.

]

public class Elephant extends Mammal
{
	private boolean fromCircus;


		public Elephant()
		{
			super();
			fromCircus = false;

		}

		public Elephant ( String n , int a ,  boolean C)
		{
			super(n,a);
			fromCircus = C;

		}

		public String speak()
		{
			return "STAMP STAMP STAMP";

		}

		public String toString()
		{
			return "ELEPHANT\n"  + super.toString() + "\nSOUND:\t" + speak() + "\nStatus:\t" + getCircusStatus();

		}

		private String getCircusStatus()
		{
			if(fromCircus = true)
				return "Circus Elephant";
					else
				return "Wild Elephant";

		}

		public void toggleCircusStatus()
		{//If it's true make it false and if it's false make it true.


			if (fromCircus = true)
				fromCircus = false;

			if (fromCircus = false)
				fromCircus = true;
		}


}

That's one way to do it, all right. There's one problem of syntax - you want to use the Double-Equals of Comparison, rather than the Single-Equals of Assignment.

But there's also a little problem of logic. What happens if fromCircus starts out as true? This can be repaired with a one-word change to your code. I bet you can figure it out.


It's also a little more complicated than is strictly necessary, but that's okay. It could be more complicated, if you tried.
Like maybe this:

public void toggleCircusStatus()
	{//If it's true make it false and if it's false make it true.
		fromCircus=(fromCircus.toString().length()/2)*2 < fromCircus;
	}

Or I'm sure I could come up with even more complications to fold in there if I were in the mood.

Anyway, was there a question in there?

Edited 6 Years Ago by jon.kiparsky: n/a

yep yep!
"=" (single equal sign) is an Assignment operator.
"==" (double equal sign) is a Conditional operator.

if (fromCircus = true)
	fromCircus = false;
if (fromCircus = false)
	fromCircus = true;

Using "=" instead of "==" in the if condition is a common programming error :p

And heyyy, i have something to say...
instead of complicating things, why not make it simpler! :p

public void toggleCircusStatus(){
	fromCircus = !fromCircus;
}
This article has been dead for over six months. Start a new discussion instead.