Java Programming (MindTap Course List)
Java Programming (MindTap Course List)
8th Edition
ISBN: 9781285856919
Author: Joyce Farrell
Publisher: Cengage Learning
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 Attached
Java question Write a Thermostat class such that a user of the Thermostat class can create an objectof Thermostat and set it to the desired temperature within a pre-specified range. If theuser tries set the temperature outside this range it should throw a TemperatureTooHighor TemperatureTooLow exception. Use inheritance to create an exception superclassTemperatureOutofRange and subclasses TemperatureTooHigh andTemperatureTooLow.Sample Tester code:Thermostat t = new Thermostat(0, 100);t. setTemp(50); // Should be OK.t.setTemp(150); // Should throw TemperatureTooHigh exception.t.setTemp(-50); // Should throw TemperatureToolLow exception.Write a Tester class to demonstrate throwing and catching of exceptions. Show that thecatch specifying the superclass catches the subclass exceptions. The order of exceptionhandlers is important. If you try to catch a superclass exception type before a subclasstype, the compiler would generate errors. Also show the re-throwing of exceptions.
JAVA Problem  – CycleFileInput   Revisit the Cycle class .  Modify your application such that the properties will be read from a text file called “Cycle.txt”.      Directions   Examine your application for the class called Cycle. Add an appropriate throws statement in the main method. Create a reference to a File class with the appropriate name of a text file (Cycle.txt). Note: Cycle.txt was created in the previous assignment, CycleFileOutput. In your code, check that the text file does exist. Input the values from the file to memory. Close the file. public class Cycle {   // Declear integer instance variable private int numberOfWheels; private int weight;   // Constructer declear class public Cycle(int numberOfWheels, int weight ) { this.numberOfWheels = numberOfWheels; this.weight = weight; }   // String method for output public String toString() { String wheel = String.valueOf(this.numberOfWheels); String load = String.valueOf(this.weight); return("No of wheels in cycle = " +…
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