Question

1. What kind of exception will be generated when the code segment below is executed? Why? int numerator 10; int denominator 0; int wholePart numerator/denominator Questions 2 and 3 refer to the Person constructor below. Person constructor has two String parameters, a first nam and a last name. the constructor initializes the e-mail address to the first letter of the first name followed by the fir five letters of the last name followed by @jc.com. If the last name has fewer than five letters, the e-mail address w be the first letter of the first name followed by the entire last name followed by Bjc.com. Examples: Name Jane Smith John Morris Mary Key E-mail address Smith@ic.com MKeyeic.com public Person(String firstName, String lastNameK myFirstName firstName mylastName lastName; emailAddress=myFirstName.substrng(0,1) + myLastName.substring(0, 5) + @jc.com. 2. What kind of exception may be thrown by this constructor? Why? 3. Which of the following calls to the Person constructor will cause the exception in Question 2 to be throw Why? a. Person scm1-new Person(Marian, Jones b. Person scm2enew Person(Joe, Thomas) c. Person scm3 new Person(Harry, Tote); d. Person scm4snew Person(, Franks e. Person scm5-new PersonEllen, Johnson)
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Question 1
The exception is ArithmeticException because we are trying to divide by zero.

Question 2
One of the exceptions can be ArrayIndexOutOfBound when the length of the string is less than 6 because in the myLastName.substring(0,5) needs to have at least string length of 6

Question 3
The option c raises and exception called ArrayIndexOutOfBound because the length of lastName is less than 6.

**Comment for any further queries.Upvote if the answer is satisfactory.

Add a comment
Know the answer?
Add Answer to:
1. What kind of exception will be generated when the code segment below is executed? Why?...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Page 1/2 ECE25100 Object Oriented Programming Lab 8: Inheritance Description: The purpose of this lab is...

    Page 1/2 ECE25100 Object Oriented Programming Lab 8: Inheritance Description: The purpose of this lab is to practice inheritance. To get credit for the lab, you need to demonstrate to the student helper that you have completed all the requirements. Question 1: Consider the following detailed inheritance hierarchy diagram in Fig. 1. 1) The Person.java constructor has two String parameters, a first name and a last name. The constructor initializes the email address to the first letter of the first...

  • Write in C++ 1. Use the following Person class (Person.cpp, Person.h). You will be writing Person...

    Write in C++ 1. Use the following Person class (Person.cpp, Person.h). You will be writing Person objects to a random access file. --------------------- Person.cpp--------------------------------- // Class Person stores customer's credit information. #include <string> #include "Person.h" using namespace std; // default Person constructor Person::Person( int idValue, string lastNameValue, string firstNameValue, int AgeValue ) { setID( idValue ); setLastName( lastNameValue ); setFirstName( firstNameValue ); setAge( AgeValue ); } // end Person constructor // get id value int Person::getID() const { return id;...

  • Create a class named Module2. You should submit your source code file (Module2.java). The Module2 class...

    Create a class named Module2. You should submit your source code file (Module2.java). The Module2 class should contain the following data fields and methods (note that all data and methods are for objects unless specified as being for the entire class) Data fields: A String object named firstName A String object named middleName A String object name lastName Methods: A Module2 constructor method that accepts no parameters and initializes the data fields from 1) to empty Strings (e.g., firstName =...

  • Requirements Create an Address Book class in Java for general use with the following behaviors: 1....

    Requirements Create an Address Book class in Java for general use with the following behaviors: 1. Constructor: public Address Book Construct a new address book object. • A contact has four fields: first name, last name, email and phone. (There could be more information for a real contact. But these are sufficient for the assignment.) . The constructor reads from the disk to retrieve previously entered contacts. If previous contacts exist, the address book will be populated with those contacts...

  • Assignment 9: Ultimate Frisbee

    The classes you will write are: Person, UltimatePlayer, Captain, Coach, and UltimateTeam. Detailed below are the requirements for the variables and methods of each class. You may need to add a few additional variables and/or methods; figuring out what is needed is part of your task for this assignment.PersonVariablesString firstName - Holds the person's first name.String lastName - Holds the person's last name.MethodsPerson(String firstName, String lastName) - Constructor that takes in String parameters representing the first and last names.int throwDisc(int pow) - returns the...

  • Introduction In this lab, you will be working with three classes: Person, Student, and Roster. Person...

    Introduction In this lab, you will be working with three classes: Person, Student, and Roster. Person and Student represent individuals with a first and last name as String class variables, and Student has an additional int class variable that represents a ID number. The Roster class represents a group of people that are objects of either the Person or Student class. It contains an ArrayList. The Person class has been completed for you with class variables, a constructor, and a...

  • Why when executed my frame does not contain what i have added to it? Here is...

    Why when executed my frame does not contain what i have added to it? Here is my code import java.awt.Panel; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTextArea; import javax.swing.JTextField; import javax.swing.JPanel; @SuppressWarnings("serial") public class AddressBook1 extends JFrame implements ActionListener {    /**    *    */       JLabel name = new JLabel("Name: ");    JLabel address = new JLabel("Address: ");    JLabel phone = new JLabel("Phone: ");    JLabel email = new JLabel("Email: ");...

  • In the processLineOfData method, write the code to handle case "H" of the switch statement such...

    In the processLineOfData method, write the code to handle case "H" of the switch statement such that: • An HourlyEmployee object is created using the firstName, lastName, rate, and hours local variables. Notice that rate and hours need to be converted from String to double. You may use parseDouble method of the Double class as follows: Double.parseDouble(rate) Call the parsePaychecks method in this class passing the Hourly Employee object created in the previous step and the checks variable. Call the...

  • Please help. I need a very simple code. For a CS 1 class. Write a program...

    Please help. I need a very simple code. For a CS 1 class. Write a program in Java and run it in BlueJ according to the following specifications: The program reads a text file with student records (first name, last name and grade). Then it prompts the user to enter a command, executes the command and loops. The commands are the following: "printall" - prints all student records (first name, last name, grade). "firstname name" - prints all students with...

  • The file Sorting.java contains the Sorting class from Listing 9.9 in the text. This class implements...

    The file Sorting.java contains the Sorting class from Listing 9.9 in the text. This class implements both the selection sort and the insertion sort algorithms for sorting any array of Comparable objects in ascending order. In this exercise, you will use the Sorting class to sort several different types of objects. 1. The file Numbers.java reads in an array of integers, invokes the selection sort algorithm to sort them, and then prints the sorted array. Save Sorting.java and Numbers.java to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT