I am working on an assignment for class, where there will be a cube, and each side will be painted one of four possible colors. There will be additional aspects required, but the issue I am having is that each side is getting set to the same color, and I am just not sure why. I will post what I have below, and it will include the methods I use to print out the result.
Thanks for any possible help
public class Cube
private Color top;
private Color bottom;
private Color left;
private Color right;
private Color front;
private Color back;
private Color painter;
top = AssignColor();
bottom = AssignColor();
left = AssignColor();
right = AssignColor();
front = AssignColor();
back = AssignColor();
private Color AssignColor()
generator = new Random();
colorVal = generator.nextInt(4) + 1;
if(colorVal == 1)
painter = Color.blue;
else if(colorVal == 2)
painter = Color.red;
else if(colorVal == 3)
painter = Color.green;
else if(colorVal == 4)
painter = Color.white;
public String colorConv()
String tempFront = "red";
if(front.getRGB() == -16776961)
tempFront = "Blue";
else if(front.getRGB() == -16711936)
tempFront = "Green";
else if(front.getRGB() == -65536)
tempFront = "Red";
else if(front.getRGB() == -1)
tempFront = "White";
public void print()
System.out.println("The top is " + colorConv());
System.out.println("The bottom is " + colorConv());
System.out.println("The left side is " + colorConv());
System.out.println("The right side is " + colorConv());
System.out.println("The front is " + colorConv());
System.out.println("The back is " + colorConv());
When posting code, make sure you use the code tags and use standard naming conventions (methods start with a lower case letter, for example).
Is it the same color each time? Or a different color, but each side gets the same color?
You'd be better off posting a short piece of runnable code and the actual output you get.
It doesn't matter if it is the same color, but it is supposed to be random, so it might be, it might not be, but each side is supposed to be determined differently. No matter how many times I run it, each side is always the same color as the rest in that instance.
The top is Red
The bottom is Red
The left side is Red
The right side is Red
The front is Red
The back is Red
That is an example of what it looks like, and that is ok, just not every time I run the code.
When you convert a color that method only checks the color of 'front'.
Are you referring to where I return the painter value, which is then associated with the side?
He is referring to your colorConv() method. Trace through every time you call it and see what it returns each time.
Originally Posted by Gligum
Ha... oh wow.... I feel bad about wasting both of your guys' time on this, I can't believe I missed that. Thanks a lot for your help both of you.