Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

please use java. Thanks! 5 Write a Color Class Create your own class called HDRC

ID: 3908174 • Letter: P

Question

please use java. Thanks!

5 Write a Color Class Create your own class called HDRColor. An HDRColor should be represented using three floating. point components to represent the red, green, and blue (RGB) components of the color. You may use the Fraction example from lecture as a reference for this step. HDR stands for high-dynamic range, which basically means that we are using double precision floating-point numbers to represent RGB components with unbounded intensity, rather than integers with a fixed upper bound. HDR is useful in image science and computer graphics for simultaneously representing very bright points in an image (i.e. the sun) and very dark points (i.e. shadows). HDR also makes it easier to accurately add, subtract, and multiply light contributions in a numerically precise and physically correct way. HDRColor should have get and set methods for the red, green, and blue attributes. You should prevent any of the attributes from being set to values less than zero. HDRColor does not need t

Explanation / Answer

Given below is the code for the question.
To indent code in eclipse , select code by pressing ctrl+a and then indent using ctrl+i
Please do rate the answer if it was helpful. Thank you

HDRColor.java
-------------
public class HDRColor {
private double red, blue, green;

public HDRColor(){
red = 0;
blue = 0;
green = 0;
}

public double getRed() {
return red;
}

public void setRed(double red) {
if(red < 0)
red = 0;
this.red = red;
}

public double getBlue() {
return blue;
}

public void setBlue(double blue) {
if(blue < 0)
blue = 0;
this.blue = blue;
}

public double getGreen() {
return green;
}

public void setGreen(double green) {
if(green < 0)
green = 0;
this.green = green;
}

public boolean equals(HDRColor other){
if(red == other.red && blue == other.blue && green == other.green)
return true;
else
return false;
}

public void add(HDRColor color){
red += color.red;
blue += color.blue;
green += color.green;
}

public void subtract(HDRColor color){
setRed(red - color.red);
setBlue(blue - color.blue);
setGreen(green - color.green);
}

public void multiply(double factor){
setRed(red * factor);
setBlue(blue * factor);
setGreen(green * factor);
}

public void divide(double factor){
if(factor != 0){
setRed(red / factor);
setBlue(blue / factor);
setGreen(green / factor);
}
}

public String toString(){
return String.format("(%.6f, %.6f, %.6f)", red, green, blue);
}
}

TestHDRColor.java
=============

public class TestHDRColor {
public static void main(String[] args) {
HDRColor c1 = new HDRColor();
HDRColor c2 = new HDRColor();

System.out.println("setting c2 to (1, 2, 3)");
c2.setRed(1);
c2.setBlue(2);
c2.setGreen(3);

System.out.println("c1 = " + c1);
System.out.println("c2 = " + c2);

System.out.println("setting red of c2 to -5");
c2.setRed(-5);
System.out.println("c2 = " + c2);

System.out.println("adding c2 to c1");
c1.add(c2);
System.out.println("c1 = " + c1);

System.out.println("multiplying c1 by 3");
c1.multiply(3);
System.out.println("c1 = " + c1);

System.out.println("dividing c1 by 0.5");
c1.divide(0.5);
System.out.println("c1 = " + c1);

System.out.println("subtracting c2 from c1");
c1.subtract(c2);
System.out.println("c1 = " + c1);

}
}

output
-----
setting c2 to (1, 2, 3)
c1 = (0.000000, 0.000000, 0.000000)
c2 = (1.000000, 3.000000, 2.000000)
setting red of c2 to -5
c2 = (0.000000, 3.000000, 2.000000)
adding c2 to c1
c1 = (0.000000, 3.000000, 2.000000)
multiplying c1 by 3
c1 = (0.000000, 9.000000, 6.000000)
dividing c1 by 0.5
c1 = (0.000000, 18.000000, 12.000000)
subtracting c2 from c1
c1 = (0.000000, 15.000000, 10.000000)