Related questions
Concept explainers
Assume there is a static method called scienceTechEngrMath that takes a String parameter. Its prototype is below:public static String scienceTechEngrMath(String department)
This method will return the answer to any department-based question, but... it will throw exceptions in the following cases:
• NullPointerException is thrown if you pass it "null" instead of an actual department string
• NotInTheDivisionException is thrown if the length of the characters in the department name is less than 7
• ThatIsInvalidDivisionException is thrown if the length of characters in the department name is more than 11 characters
private static void askDepartment(String question) {
try {
String response = scienceTechEngrMath(question);
System.out.println("1");
}
catch (NullPointerException e) {
System.out.println("3");
}
catch (NotInTheDivisionException e) {
System.out.println("5");
}
finally {
System.out.println("7");
}
}
public static void main(String[] args) {
try {
askDepartment ("Which Department do you belong to?");
askDepartment ("Arts?");
askDepartment ("Business Development?");
System.out.println("5");
}
catch (NotInTheDivisionException e)
{
System.out.println("6");
}
catch (ThatIsInvalidDivisionException e){
System.out.println("8");
}
finally {
System.out.println("10");
}
System.out.println("9");
}
}
Trending nowThis is a popular solution!
Step by stepSolved in 5 steps with 2 images
- FilelO 01: Write a Message Write a FileI001 class with a method named writeMessage() to takes message as a String and a filename (as a String) (in that order). Have the method, write the message to the filename. Your code will either need to 1) catch all checked exceptions or 2) use the throws keyword. public class FileI001{ public void writeMessage( String message, String filename ){arrow_forwardThere is no maximum number of arguments that may be used inside a catch block since this kind of block does not have a parameter restriction.arrow_forwardIn python and include doctring: First, write a class named Movie that has four data members: title, genre, director, and year. It should have: an init method that takes as arguments the title, genre, director, and year (in that order) and assigns them to the data members. The year is an integer and the others are strings. get methods for each of the data members (get_title, get_genre, get_director, and get_year). Next write a class named StreamingService that has two data members: name and catalog. the catalog is a dictionary of Movies, with the titles as the keys and the Movie objects as the corresponding values (you can assume there aren't any Movies with the same title). The StreamingService class should have: an init method that takes the name as an argument, and assigns it to the name data member. The catalog data member should be initialized to an empty dictionary. get methods for each of the data members (get_name and get_catalog). a method named add_movie that takes a Movie...arrow_forward
- 1. When does the + operator concatenate instead of add? What happens if you try to use + on a string with an integer? Why do you think this happens? 2. If a string has 10 characters, what is the index of the last character? 3. Explain why this code causes an exception: Animal = "Tiger" Animal[0] = "L"arrow_forwardWhat is the upper limit on the number of arguments that a catch block can accommodate?arrow_forwardEHPD Walk-Through Video Terms & Conditions Registration- Subject Expertise Verification Guidelines Training O Search ehpd.cheggindia.com 13 centrat Shaki Subject Test Note: class Main { } Schölerchippe bes What is the output of the following code? You a } public static int fun(int x) { attempting questi n 8 out of 16 a. Chegg493 b. Chegg19 c. Error d. Chegg-19 byte y (byte) x; return y; public static void main(String[] args) System.out.println("Chegg" + fun (493)); A SAMSUNOarrow_forward
- Text book imageDatabase System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationText book imageStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONText book imageDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- Text book imageC How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONText book imageDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningText book imageProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education