I am working on a fairly simple program where I have a colour change three times using the red green blue spectrum. The problem is that I keep getting a result of zero no matter what I do. Does anyone have any suggestions?
import java.awt.*; class RectangleMain { public static void main (String[] args) { ColouredRectangle blocky = new ColouredRectangle(50, 100, 20, 40, Color.red); System.out.println(blocky.getColour()); blocky.mixColour(Color.blue); System.out.println(blocky.getColour()); blocky.mixColour(Color.black); System.out.println(blocky.getColour()); } }
import java.awt.*; public class ColouredRectangle extends Rectangle { ColouredRectangle (int x, int y, int width, int height, Color colour) { super (x, y, width, height); } private Color colour; private int rVal; private int gVal; private int bVal; public void setColour(int r, int g, int b) { colour = new Color(r,g,b); rVal = r; gVal = g; bVal = b; } public String getColour() { return ("blocky's colour is java.awt.Color[Red = " + rVal + ", Green = " + gVal + ", Blue = " + bVal + "]"); } public void mixColour(Color addColour) { int newRed = (addColour.getRed() + rVal) % 256; int newGreen = (addColour.getGreen() + gVal) % 256; int newBlue = (addColour.getBlue() + bVal) % 256; colour = new Color(newRed, newGreen, newBlue); } }