Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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!
ColorDriver class: SimpleColor class:
ColorWithAlpha Extends SimpleColor Our classes shouldn't start from scratch when we design them for use in our applications, and we have an opportunity to realize the often-elusive goal of code reuse here in this lab. If you still have the SimpleColor class from a previous lab, you should locate that now. The purpose of this lab is to get you started with inheritance by building new classes from existing classes. We'll build a class that can represent an RGB value and an Alpha value, used in determining transparency. Define this new class using the following format: "public class ColorWithAlpha extends SimpleColor ", and make sure SimpleColor.java is in the same directory as your new ColorWithAlpha.java file. Even though the class is empty, it should compile just fine, and in fact, contains all the methods and data defined in the SimpleColor superclass. (1) Download the ColorDriver.java class (2) Find your old SimpleColor class, or build a new SimpleColor superclass now (3) Build a new subclass called ColorWithAlpha, and extend SimpleColor. (4) Add a new int called "alpha" for use in determining the color's alpha channel a. This too will be clamped from 0-255, representing 8 bits of storage. (5) Define getters and setters for the new alpha channel (6) Build one constructor that takes only an alpha value a. This should initialize RGB to 0 (7) Build a second (overloaded) constructor that takes 4 values (RGBA) and calls the superclass constructor to initialize the RGB values a. The first line of your constructor will be "super(r,g,b);" i. What does this line accomplish? What function are we calling? (8) Build a third (overloaded) copy constructor that takes an existing ColorWithAlpha object as input (9) Override the toString) function to print out your "(R,G,B,A)" values as we do below a. What does the following call to super do? public String tostring) [ return super.toString)+ ", alpha:"+ alpha; (10)Override the equals(Object o) function to determine if two ColorsWithAlpha are equal a. Use "for primitives such as your alpha amount, and use ".equals()" with objects such as SimpleColors (11) Run the driver to test your new ColorWithAlpha subclassStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started