Java: An Introduction to Problem Solving and Programming (7th Edition)
Java: An Introduction to Problem Solving and Programming (7th Edition)
7th Edition
ISBN: 9780133766264
Author: Walter Savitch
Publisher: PEARSON
bartleby

Concept explainers

Question
Book Icon
Chapter 9.2, Problem 15STQ
Program Plan Intro

Program plan:

  • • Create a class named “CoreBreachException” that extends “Exception”.
    • ○ Define a default constructor that calls the parent class’s method using “super ()” by passing a message.
    • ○ Define a parameterized constructor that calls the parent class’s method using “super ()” by passing a message that is given as the argument.
  • • Create a class named “Main”.
    • ○ Define the “main ()” method.
      • ■ Create an object “e” for the class and pass a string as its argument.
      • ■ Create an object “e1” for the class that does not contain any argument.
      • ■ Get and print the message using the method “e.getMessage()”.
      • ■ Get and print the message using the method “e1.getMessage()”.

Blurred answer
Students have asked these similar questions
Define an exception class called CoreBreachException. The class should have a default constructor. If an exception is thrown using this zero- argument constructor, getMessage should return "Core Breach! Evacuate Ship!" The class should also define a constructor having a single parameter of type String. If an exception is thrown using this constructor, getMessage should return the value that was used as an argument to the constructor.
Define an exception class called CoreBreachException. The class should have a default constructor. If an exception is thrown using zero-argument constructor, getMessage should return "Cor Breach Evacuation Ship!" The class should also define a constructor having a single parameter of type String. If an exception is thrown using constructor, getMessage should return the value that was used as an argument to constructor.
Develop an exception class named InvalidMonthException that extends the Exception class.   Instances of the class will be thrown based on the following conditions: The value for a month number is not between 1 and 12 The value for a month name is not January, February, March, … December Develop a class named Month.  The class should define an integer field named monthNumber that holds the number of a month.  For example, January would be 1, February would be 2, and so forth.  In addition, provide the following methods: A no-argument constructor that sets the monthNumberto 1. An overloaded constructor that accepts the number of the month as an argument.  The constructor should set the monthNumberfield to the parameter value if the parameter contains the value 1 – 12.  Otherwise, throw an InvalidMonthException exception back to the caller.  The exception should note that the month number was incorrect. An overloaded constructor that accepts a string containing the name of the month,…

Chapter 9 Solutions

Java: An Introduction to Problem Solving and Programming (7th Edition)

Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning