In cityFinals() you should call exceptionGenerator.runCourse(). If no exception
ID: 3798495 • Letter: I
Question
In cityFinals() you should call exceptionGenerator.runCourse(). If no exception is thrown, print out "No exception thrown". If the call to runCourse() resulted in a checked exception, print out "Caught checked exception". If runCourse() resulted in an unchecked exception, print out "Caught unchecked exception".
In mountMidoriyama() you will handle the results of the grand finale. If the throwChecked parameter is true, your code should raise a RopeClimbException. If the throwUnchecked parameter is true instead, your code should raise a TimeException. If both parameters are false, nothing else needs to be done.
Use @param mentioned in comments. Code must only be written in each of the methods. No additional methods necessary.
Explanation / Answer
package AmericanExceptionWarrior;
public class AmericanExceptionWarrior {
public void cityFinals(QualifyingCourse exceptionGenerator)
{
exceptionGenerator.runCourse();
}
public void mountMidoriyama(boolean throwChecked, boolean throwUnchecked) throws RopeClimbException,TimeException{
if(throwChecked==true)
{
throw new RopeClimbException();
}
else if(throwUnchecked==true)
{
throw new TimeException();
}
else
{
System.out.println("No Exceptions thrown");
}
}
}
====================================================================================
package AmericanExceptionWarrior;
public class QualifyingCourse
{
public void runCourse()
{
AmericanExceptionWarrior ac=new AmericanExceptionWarrior();
try
{
ac.mountMidoriyama(true, false);
}
catch(RopeClimbException rC)
{
System.out.println("Caught checked exception");
}
catch(TimeException tE)
{
System.out.println("Caught unchecked exception");
}
}
}
=======================================================================================
package AmericanExceptionWarrior;
public class RopeClimbException extends Exception
{
/**
*
*/
private static final long serialVersionUID = 1L;
RopeClimbException()
{
super();
}
}
=======================================================================================
package AmericanExceptionWarrior;
public class TimeException extends Exception
{
/**
*
*/
private static final long serialVersionUID = -4913467822041967919L;
TimeException()
{
super();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.