Creating a return statement

I'm trying to create a return statement with all of my conditions, but I cannot figure out how to do it properly.

My plan is that once a condition is met, the method will return that condition.

For example:

if the "o" matches the condition, the method would have to return "o"

Here's my code.

public Actor createActor(char c)throws UnknownActorException

{

if(c != ('*'))

thrownew UnknownActorException("Cannot be an asterisk");

if(c != (' '))

thrownew UnknownActorException("Cannot have a space");

if(c != ('-'))

thrownew UnknownActorException("Cannot have a space");

if(c != ('o'))

thrownew UnknownActorException("Cannot have a space");

}

[1503 byte] By [vopoa] at [2007-11-26 22:22:29]
# 1
But, as it is defined in the code you posted, your method is supposed to return an Actor, not a String.Would you mind elaborate a bit on what the method is supposed to do?Anyway, in order to get a String out of a char, you could use: String.valueOf(char c);
TimTheEnchantora at 2007-7-10 11:21:01 > top of Java-index,Java Essentials,Java Programming...
# 2
The method's task is find the exception.Once the exception is selected from the following condistions,It has to return that conditional statement.I hope it helps in what I'm trying to do.
vopoa at 2007-7-10 11:21:01 > top of Java-index,Java Essentials,Java Programming...
# 3
so the return type should be void ?What do you mean by "return conditional statement" ?Do you mean return the Exception if it happened ?
rym82a at 2007-7-10 11:21:01 > top of Java-index,Java Essentials,Java Programming...
# 4
Do you mean return the Exception if it happened ?Yes this is what i want to do.Sorry for not being too specific.
vopoa at 2007-7-10 11:21:01 > top of Java-index,Java Essentials,Java Programming...
# 5
In general, [url= http://java.sun.com/docs/books/tutorial/essential/exceptions/index.html]Exceptions[/url] are not supposed to be returned, but thrown.
TimTheEnchantora at 2007-7-10 11:21:01 > top of Java-index,Java Essentials,Java Programming...
# 6
So your method's return type should be voidPut a try-catch block when calling this method.You may also put some println statement or handling in catch block
rym82a at 2007-7-10 11:21:01 > top of Java-index,Java Essentials,Java Programming...
# 7
> The method's task is find the exception.Then, why is it called createActor ?I still don't get what this method is supposed to do (would you mind posting a formal description.)For example, if I call createActor('o'), what should I get in return ?
TimTheEnchantora at 2007-7-10 11:21:01 > top of Java-index,Java Essentials,Java Programming...
# 8
> Then, why is it called createActor ?Cause it creates an exceptional actor :)
quittea at 2007-7-10 11:21:01 > top of Java-index,Java Essentials,Java Programming...
# 9
> > Then, why is it called createActor ?> > Cause it creates an exceptional actor :)Ah, so [url= http://en.wikipedia.org/wiki/Special:Search?search=Best+Actor+Awards]this[/url] might be helpful then.
TimTheEnchantora at 2007-7-10 11:21:01 > top of Java-index,Java Essentials,Java Programming...