Question
Note that colors from C can be used more than once and that not all colors in C must be used. An example of a
Note that colors from C can be used more than once and that not all colors in C must be used. An example of a solid cube over the set of colors C = {Red, Green, Blue} is: Top - Green Front - Green Right - Blue Back - Green Left - Blue Bottom - Green
Notice that the color Red is not used in this example. Also assume that, before painting, each face of the cube is indistinguishable from each of the other five faces (e.g. ignore the wood-grain on the cube faces in the above image). Since what which cube faces we call Top, Front, Right, Back, Left, and Bottom above is arbitrary, notice that another representation of the same cube is: Top - Green Front - Blue Right - Green Back - Blue Left - Green Bottom - Green Furthermore, we will define two cubes to be equal if, and only if, one cube can be physically reoriented so that the two cubes look identical to a human observer. So, there is only one solid cube over the set of colors C = {Red, Blue} with exactly one Blue face, namely: Top - Red Front - Red Right - Red Back - Blue Left - Red Bottom - Red All other cubes with one Blue face are equivalent to this one since, given a cube with exactly one Blue face, we can reorient this cube so that the Back face is Blue You are to write code which, given a set of colors C, will compute the set of pairwise distinct (i.e., non-equal) solid cubes over the set C. In particular, write a method with the following signature: public static Set
Please, use all the files provided to write and fix the code that works, thanks!
Here is the interface:
package model;
import java.util.Set;
public interface Cube {
public Set
}
Here is the CubeImpl file, please, fix and complete it:
package model;
import java.util.HashSet;
import java.util.Set;
public class CubeImpl implements Cube
{
private CubeNet representativeNet;
public CubeImpl (CubeNet cubeNetRepresentative)
{
assert cubeNetRepresentative != null : "cubeNetRepresentative is null!";
this.representativeNet = cubeNetRepresentative;
}
@Override
public Set
{
Set
allNets.add(this.representativeNet);
// Here you can generate all the possible nets for the cube by
// rotating the representative net along its different axes and
// adding each resulting net to the set of all nets.
// You can use the different methods available in the CubeNet class
// to perform the rotations and generate the new nets.
return allNets;
}
}
package model;
another interface:
import java.awt.Color;
public interface CubeNet {
public Color getTop();
public Color getFront();
public Color getRight();
public Color getBack();
public Color getLeft();
public Color getBottom();
}
package model;
import java.awt.Color; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set;
public class CubeNetImpl implements CubeNet { private Color top; private Color front; private Color right; private Color left; private Color bottom; private Color back; private Set
top = faceToColorMap.get(Face.TOP); front = faceToColorMap.get(Face.FRONT); right = faceToColorMap.get(Face.RIGHT); left = faceToColorMap.get(Face.LEFT); bottom = faceToColorMap.get(Face.BOTTOM);
if (CALCULATE_POSSIBLE_MAPS_ONE_TIME) { long startTime = System.currentTimeMillis(); allPossibleMaps = generateAllPossibleMaps(); long endTime = System.currentTimeMillis(); timeSpentInSetAddMillis += endTime - startTime; CALCULATE_POSSIBLE_MAPS_ONE_TIME = false; }
if (CALCULATE_HASHCODE_ONE_TIME) { long startTime = System.currentTimeMillis(); hashCode(HASHCODE_LEVEL); long endTime = System.currentTimeMillis(); timeSpentHashCode += endTime - startTime; CALCULATE_HASHCODE_ONE_TIME = false; } } @Override public Color getTop() { return top; }
@Override public Color getFront() { return front; }
@Override public Color getRight() { return right; }
@Override public Color getBack() { return back; }
@Override public Color getLeft() { return left; }
@Override public Color getBottom() { return bottom; } public int getDistinctColorCount() { Set
private Set
// @Override // public int hashCode() { // if (hashCode != null) { // return hashCode; // } // }
//Improving on the inherited hashCode() is mandatory //to get improved performance //Also, whenever you change hashCode() you probably //need to change equals() to ensure that the "equals()/hashCode() //contract" is satisfied public int hashCode(int level) { int hashCode = 0; if(this.hashCode != null) { hashCode = this.hashCode(); } else if (level == 0) { hashCode = 0; } else if (level == 1) { hashCode = (top.getRGB() + bottom.getRGB() + left.getRGB() + front.getRGB() + back.getRGB() + right.getRGB()); } else if(level == 2) { hashCode = getDistinctColorCount(); } else { assert level == 0 : "level = " + level + "is uniterpretable"; } return hashCode; } //Improving on the inherited equals() is mandatory //to get improved performance //Also, whenever you change equals() you probably //need to change hashCode() to ensure that the "equals()/hashCode() //contract" is satisfied public boolean equals(Object obj) { throw new RuntimeException("NOT IMPLEMENTED YET!"); } //Implement a decent toString() for yourself during development @Override public String toString() { return "CubeNetImpl {" + "top=" + top + ", front=" + front + ", right=" + right + ", back=" + back + ", left=" + left + ", bottom=" + bottom + '}'; }
Another class:
package model;
import java.awt.Color; import java.util.Set;
public class CubeSolver_Opinca { private CubeSolver_Opinca() { assert false : "DO NOT INSTANTIATE!"; } public static Set
the enum:
package model;
public enum Face {
TOP, FRONT, RIGHT, BACK, LEFT, BOTTOM;
}//DON'T CHANGE THE INTERFACE
Step 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