Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

public class ExceptionWarrior { /** * {@code public void runCourse() throws Rope

ID: 3753238 • Letter: P

Question

public class ExceptionWarrior {

/**

   * {@code public void runCourse() throws RopeClimbException, TimeException}. // RopeClimbException is checked; TimeException is unchecked.<br/>

   * This method calls {@code athlete.runCourse();} and return true when {@code runCourse()} completes normally (this is the city finals winner).

   * The rope climb is the first obstacle and the producers need to know about the athletes who fail at this.

   * If a {@code RopeClimbException} gets raised by {@code runCourse()}, allow the exception to continue to the calling method WITHOUT handling it.

   * The {@code TimeException} is raised by {@code runCourse()} when the athlete is not the fastest. When this happens, handle the exception and

   * return false.

   *

   * @param athlete Instance whose runCourse() method is used to see if they advance from the city finals.

   * @return True, if the athlete wins the city finals; false otherwise.

   * @throws RopeClimbException Exception that gets passed on from those athletes unable to complete the first obstacle.

   */

public boolean cityFinals(AEWCompetitor athlete) {

}

/**

   * {@code public void runCourse() throws RopeClimbException, TimeException}. // RopeClimbException is checked; TimeException is unchecked.<br/>

   * This method calls {@code athlete.runCourse();} and return true when {@code runCourse()} completes normally (this will be the overall champion).

   * On this year's Mount Midoriyama, the rope climb is the LAST obstacle and so does not require the producers attention.

   * If a {@code RopeClimbException} gets raised by {@code runCourse()}, handle the exception and return false.

   * Losing athletes may get invited back for a future season. If a {@code TimeException} is raised by {@code runCourse()}, allow the exception to continue to the calling method WITHOUT handling it.

   *

   * @param athlete Instance whose runCourse() method is used to see if they are grand champion.

   * @return True, if the athlete wins the grand championship; false otherwise.

   * @throws TimeException Exception that gets passed on from losing athletes who complete the course.

   */

public boolean mountMidoriyama(AEWCompetitor athlete) {

}

}

For this homework problem, you will need to complete the following 2 methods in AmericanExceptionWarrior (including adding any throws clauses that are required for compilation): cityPinals() calls athlete.runCourse(): and return true when runCourse) completes normally. If a RopeclimbException gets raised by runcourse), allow the exception to continue to the calling method WITHOUT handling it. When the called method raises a TimeException, handle the exception and return false mountMidoriyama calls athlete.runcourse) and return true when runcourse) completes normally. If a TimeException gets raised by runcourse), allow the exception to continue to the calling method WITHOUT handling it. When the called method raises a RopeClimbException, handle the exception and return false

Explanation / Answer

ExceptionWarrior.java


public class ExceptionWarrior {
public boolean cityFinals(AEWCompetitor athlete) {
try{
athlete.runCourse();
}catch (TimeException te) {
return false;
} catch (RopeClimbException e) {
}
return true;
}
public boolean mountMidoriyama(AEWCompetitor athlete) {
try{
athlete.runCourse();
}catch (TimeException e) {
} catch (RopeClimbException re) {
return false;
}
return true;
}
}


AEWCompetitor.java


public class AEWCompetitor {
public String name;
public int len;
public AEWCompetitor(String name){
this.name =name;
this.len = name.length();
}
public void runCourse() throws RopeClimbException, TimeException{
System.out.println("Running the course");
if(this.len == 4){
throw new TimeException();
}
if(this.len == 9){
throw new RopeClimbException();
}
}
}

Main.java


import java.util.ArrayList;
public class Main {
public static void main(String arg[]) {
AEWCompetitor athlete1 = new AEWCompetitor("RunnerA");
AEWCompetitor athlete2 = new AEWCompetitor("RunnerB");
AEWCompetitor athlete3 = new AEWCompetitor("RunnerC");
AEWCompetitor athlete4 = new AEWCompetitor("RunnerD");
AEWCompetitor athlete5 = new AEWCompetitor("Time");
AEWCompetitor athlete6 = new AEWCompetitor("RopeClimb");
ArrayList<AEWCompetitor> list = new ArrayList<AEWCompetitor>();
list.add(athlete1);
list.add(athlete2);
list.add(athlete3);
list.add(athlete4);
list.add(athlete5);
list.add(athlete6);
ExceptionWarrior obj = new ExceptionWarrior();
for(AEWCompetitor i : list){
boolean cityF = obj.cityFinals(i);
boolean mount = obj.mountMidoriyama(i);
System.out.println("CityFinals returned : "+cityF + " MountMidoriyama returned : "+mount + " for Athelete : "+i);
}
}
}


RopeClimbException.java


public class RopeClimbException extends Exception {
public RopeClimbException(){
}
}


TimeException.java


public class TimeException extends Exception {
public TimeException() {
}
}