EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
8th Edition
ISBN: 9781305480537
Author: FARRELL
Publisher: CENGAGE LEARNING - CONSIGNMENT
bartleby

Concept explainers

Question
Book Icon
Chapter 12, Problem 6PE
Program Plan Intro

Display course and appropriate message

Program plan:

Filename: “CourseException.java”

  • Define “CourseException” class which extends from “Exception” class
    • Define the constructor
      • Call the super method.

Filename: “Course.java”

  • Define the “Course” class
    • Declare the required variables and set the values
    • Define the default constructor
      • Set the values
    • Define the parameterized constructor
      • Set the values
    • Check the length of the department
      • Append the string to the “msg” variable
    • Check the “num” value is less than “LOW_NUM” or greater than “HIGH_NUM”
      • Append the string to the “msg” variable
    • Check “msg” is not equal to empty string.
      • Throw an exception.
  • Define “toString” method
    • Return the value

Filename: “ThrowCourseException.java”

  • Define the class “ThrowCourseException”
    • Define the “main” method
      • Create an object for “Course” class
      • Declare the variables and set the required values to the variables
      • Iterate “for” loop until it reaches length of the “course”
        • Set the values to the object
      • Iterate “for” loop until it reaches length of the “course”
        • In “try” block, set the values
        • In “catch” block, display the course and error
      • Display the course values

Blurred answer
Students have asked these similar questions
Create a CourseException class that extends Exception and whose constructor receives a String that holds a college course’s department (for example, CIS), a course number (for example, 101), and a number of credits (for example, 3). Save the file as CourseException.java. Create a Course class with the same fields and whose constructor requires values for each field. Upon construction, throw a CourseException if the department does not consist of three letters, if the course number does not consist of three digits between 100 and 499 inclusive, or if the credits are less than 0.5 or more than 6. Save the class as Course.java. Write an application that establishes an array of at least six Course objects with valid and invalid values. Display an appropriate message when a Course object is created successfully and when one is not. Save the file as ThrowCourseException.java.
Create a CourseException class that extends Exception and whose constructor receives a String that holds a college course’s department (for example, CIS), a course number (for example, 101), and a number of credits (for example, 3). Save the file as CourseException.java. Create a Course class with the same fields and whose constructor requires values for each field. Upon construction, throw a CourseException if the department does not consist of three letters, if the course number does not consist of three digits between 100 and 499 inclusive, or if the credits are less than 0.5 or more than 6. Save the class as Course.java. Write an application that establishes an array of at least six Course objects with valid and invalid values. Display an appropriate message when a Course object is created successfully and when one is not. Save the file as ThrowCourseException.java.  Modify the CourseException class to extend RuntimeException class and identify the differences.
in java Define the class InvalidSideException, which inherits from the Exception class. Also define a Square class, which has one method variable -- an int describing the side length. The constructor of the Square class should take one argument, an int meant to initialize the side length; however, if the argument is not greater than 0, the constructor should throw an InvalidSideError. The Square class should also have a method getArea(), which returns the area of the square.Create a Driver class with a main method to test your classes. Your program should prompt the user to enter a value for the side length, and then create a Square object with that side length. If the side length is valid, the program should print the area of the square. Otherwise, it should catch the InvalidExceptionError, print "Side length must be greater than 0.", and terminate the program. screenshot shows output
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
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning