EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
9th Edition
ISBN: 9781337671385
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
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
Java Programming: Below is the lexer, shank and token files along with the shank.txt file. The shank file is the main method file. The lexer must break up the input text stream into lexemes and return a token object for each one in the shank.txt file. Make sure to fix the errors in the lexer.java file and show the complete code for lexer.java.There must be no error in the code at all. Run the whole code and show the output which the shank.txt must be printed out in the terminal. Attached is the rubric.   Lexer.java package mypack;   import java.util.HashMap;import java.util.List;import mypack.Token.TokenType; public class Lexer { private static final int INTEGER_STATE = 1;private static final int DECIMAL_STATE = 2;private static final int IDENTIFIER_STATE = 3;private static final int SYMBOL_STATE = 4;private static final int ERROR_STATE = 5;private static final int STRING_STATE = 6;private static final int CHAR_STATE = 7;private static final int COMMENT_STATE = 8; private static final…
write a java programme: Vehicle class:First create an abstract Vehicle class that contains code common to all of the vehicles.1. Vehicle class has a color, IDnumber, and a model.2. Throw an exception named “InputNotCorrectException” if the IDnumber is negative.3. The accessor and mutator methods for all three data fields.4. Also include a void wheels() method which is declared abstract. Runnable interface:1.Deaclare an abstract method named HowToRun() which has a return type of void. Car class:Car class is a subclass of Vehicle which implements the Runnable interface.1. Write a class called Car which extends the Vehicle class and implements the Runnable interface.2. Override the equals method in the Object class. Two Car objects are equal if their models are thesame.3. In the Car class override the wheels() method to display “A car has four wheels”.4. A method named toString() that returns a string description for the car.5. Override the HowToRun() method to display “A car runs with…
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