Question: Please help me code the following in: JAVA Please use many COMMENTS and read the task THOROUGHLY! Full points will be awarded, thanks in advance!
Please help me code the following in: JAVA
Please use many COMMENTS and read the task THOROUGHLY!
Full points will be awarded, thanks in advance!
SimpleColor class:
ColorException Extends RuntimeException As programs execute, they may encounter exceptional situations in which they could either try to recover or simply terminate due to the situation at hand. We're going to make a specific type of exception for our SimpleColor (and ColorWithAlpha) class, in the event the user tries to set any channel to anything outside the range [0,255], inclusive. Note that this class will be only a handful of lines, and demonstrates how inheritance can quickly produce fully functioning classes in a short amount of time. 1. Create a new project for this lab Define a new class called ColorException Build a default, no-arg constructor that contains only one line Overload your constructor with a second constructor that takes a String "msg" as input. Then, 2. a. This class should include "extends RuntimeException" 3. a. super( "An error occurred in Color"); 4. the only line of code in this function will be: a. super(msg); 5 In your old SimpleColor class (and in your new ColorWithAlpha class below), in the setter functions (setRed, setGreen, setBlue, etc.), throw a new ColorException if the user tries to set a value outside of [0,255], inclusive. To test your exception, make a main in ColorException and include the line: 6. a. throw new ColorException( "A test in main")
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
