The method below takes an array of Jeroos and should throw an exception if any Jeroo in the array is null or if any is facing North. In the conditionals below... • If a jeroo in the array is null, throw an IllegalArgumentException • If a jeroo is facing north, throw an illegalstateException The exception should contain a message that reports if the jeroo was null or facing north. These messages have been provided for you in the conditionals below. If no jeroos are bad, this method does not need to do anything and does not need to return anything. Your Answer: Feedback Your feedback will appear here when you check your answer. 4 1 public void validateJeroos (Jeroo[] jeroos) 2. throws IllegalStateException, IllegalArgumentException 3{ for (Jeroo jeroo : jeroos) 5 { 6 if (jeroo == null) 7 { 8 String message "Jeroo is Null"; 9 10 } 11 else if (jeroo.isFacing(NORTH)) 12 { 13 String message = "Jeroo is facing North"; 14 15 } 16 } 17 18 } 19 Check my answer! Reset Next exercise
The method below takes in a String parameter representing a username. It should throw an Exception if the username is less than 3 characters long. The method correctly throws the exception, but something is still missing. Fix the problem. Your Answer: Feedback Your feedback will appear here when you check your answer. 1 public String validateUser(String userName) 2 { 3 if (userName.length() < 3) 4 { 5 throw new Exception("userName is too short"); 6 } 7 return userName; 8} 9 Check my answer! Reset Next exercise
The validateJeroo() method takes in an array of Jeroo objects and could throw two different exceptions. If a Jeroo in the array is null, it will throw an IllegalArgumentException. If a Jeroo is facing North, it will throw an IllegalstateException. Add two catch clauses to the try block in the method to: Return -1 if any Jeroos are null, or return -2 if any Jeroo is facing North. The method already returns 0 on normal operation. Your Answer: Feedback Your feedback will appear here when you check your answer. 1 public int callValidateJeroos (Jeroo[] jeroos) 2 { try 4 { 5 validateJeroos(jeroos); } return 0; 8} Nm 000 Check my answer! Reset Next exercise
The following code runs a method called validateUser() that will throw an IllegalArgumentException if a username (passed in as a parameter) is less than three letters long. This method will not return any value and will do nothing if no error is thrown. Below, a try/catch block has been implemented to make the username longer than 3 characters if it is too short. Add in a finally block to add "user" onto the end of each user name. Your Answer: Feedback Your feedback will appear here when you check your answer. 9 1 public String validuserName(String userName) 2 { 3 String result = userName; 4 String suffix = ".user"; try 6 { validateUser(userName); 8 catch (IllegalArgumentException badUser) 10 { 11 while (result.length() < 3) 12 13 result += 14 } 15 } 16 17 return result; 18} 19
The method below takes an array of Jeroos and should throw an exception if any Jeroo in the array is null or if any is f
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
The method below takes an array of Jeroos and should throw an exception if any Jeroo in the array is null or if any is f
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!