Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this project, you will be creating a Rubik's Cube simulator. Setup Before beginning the lab you will need to do the following things: Can

In this project, you will be creating a Rubik's Cube simulator.

Setup

Before beginning the lab you will need to do the following things:

  1. Can you create a folder within your class folder and name it Rubik. All of your files for this project must be saved in thisCIS36A/Rubikdirectory.
  2. Download the following files into yourCIS36A/Rubikdirectory:
    • RubikRunner.javaDownload RubikRunner.java
    • RubikCube.javaDownload RubikCube.java
    • RubikFace.javaDownload RubikFace.java
  3. Always compile and run RubikRunner.java class. It will automatically compile the other supporting classes.


Submission

Submit all of your final source files

Submit sample console runs for all of parts below.

Part 1 - Create a Cube

You will be given the main program class (RubikRunner). You will not need to change RubikRunner.

You will also be given the skeleton to the Rubik's Cube class (RubikCube) and a placeholder class describing the face of a Rubik's Cube (RubikFace). You will not have to change RubikFace.

Your assignment is to:

1) Implement theRubikCubeconstructor. The constructor takes no arguments and creates and populates an array of RubikFace objects. Each RubikFace should have its own color (ex: full color name: "White").

2) Implement the toString() method of RubikCube. The output of the method should be the net of the cube, with the front face in the center, as shown below.

Sample Run


W B O G Y R


Colors:

W: White

O: Orange

B: Blue

Y: Yellow

R: Red

You must use thefacesarray in your toString method to receive full credit.


Part 2 - Rotate the entire Cube

In this part, you will write code to rotate the cube. You will need to implement a loop asking the user what direction to rotate inRubikRunner, and implement left(), right(), up() and down() methods inRubikCubethat will rotate the cube in the given direction. For example, if the cube looks like:

W B O G Y R

and you rotated left, the cube would now look like:

W O G R Y B

Your assignment is to:

1) RubikCube.java - Implement the 4 commands as void methods - left(), right(), up(), down()

2) RubikRunner.java - add a command loop that asks the user for which direction to turn the cube, including the option to exit the program. After each turn is executed, print out the cube.

3)RubikFace.java - still nothing to do on this one, yet.

Sample Run

W B O G Y R What direction? q to quit What direction [right, left, up, down]: left W O G R Y B What direction? q to quit What direction [right, left, up, down]: right W B O G Y R What direction? q to quit What direction [right, left, up, down]: up O B Y G R W What direction? q to quit What direction [right, left, up, down]: down W B O G Y R What direction? q to quit What direction [right, left, up, down]: q Part 3 - Nine-facet version of each face

In this part, you will be working mostly with the RubikFace class.

Your assignment is to:

1) RubikFace - Add a 3x3 array to RubikFace that will hold the colors for each of the 9 facets on the face. For now, set each of the facets to be the same color as the face. You will also have to modify thetoStringmethod to return a 3x3 grid of colors. If, for example, the color of the face was Red, yourtoStringmethod should return:

R R R R R R R R R

2) Update any methods inRubikRunnerorRubikCubethat require updating as a result of this change.

Starting with this activity, you need to comment on your code.

Sample Run

W W W W W W W W W B B B O O O G G G B B B O O O G G G B B B O O O G G G Y Y Y Y Y Y Y Y Y R R R R R R R R R What direction? q to quit What direction [right, left, up, down]: left W W W W W W W W W O O O G G G R R R O O O G G G R R R O O O G G G R R R Y Y Y Y Y Y Y Y Y B B B B B B B B B What direction? q to quit What direction [right, left, up, down]: up G G G G G G G G G O O O Y Y Y R R R O O O Y Y Y R R R O O O Y Y Y R R R B B B B B B B B B W W W W W W W W W What direction? q to quit What direction [right, left, up, down]: down W W W W W W W W W O O O G G G R R R O O O G G G R R R O O O G G G R R R Y Y Y Y Y Y Y Y Y B B B B B B B B B What direction? q to quit What direction [right, left, up, down]: right W W W W W W W W W B B B O O O G G G B B B O O O G G G B B B O O O G G G Y Y Y Y Y Y Y Y Y R R R R R R R R R Part 4 - Shuffled Cube

In this part, you will write the first step of code to rotate one face of the Rubik's Cube. When you rotate an actual Rubik's Cube, the front rows on the sides move with the face you're rotating - we're not doing that. yet ...

You will be working mostly withRubikFacein this exercise.

Your assignment is to:

1) Modify the constructor for RubikFace. RubikFace will need to have randomly generated colors in each of the cells, except the center cell which will remain the color that is passed through to the constructor.

2) Modify RubikRunner to accept 2 new commands: cw (for clockwise) and ccw (for counter clockwise). Each of those commands will call the corresponding new RubikCube methods that you will create. Those new RubikCube methods (ccw() and cw()) will call the corresponding new methods in RubikFace. Note that the rotated face is always the front face (face 2).

The RubikFace methods will rotate the face 90 degrees in the indicated direction.

Note:if you did not get your faces to print out correctly in Part 3, substitute printing just the front face in yourtoStringfor RubikCube.


Sample Run

G Y Y G W W Y O B Y W R G Y R B W O B B Y R O G G G G R W B R B W G B R B O R O Y Y Y O R W W R B R B Y B O What direction? q to quit What direction [right, left, up, down]: cw G Y Y G W W Y O B Y W R R R G B W O B B Y B O Y G G G R W B W G R G B R B O R O Y Y Y O R W W R B R B Y B O What direction? q to quit What direction [right, left, up, down]: cw G Y Y G W W Y O B Y W R W B R B W O B B Y G O R G G G R W B R Y G G B R B O R O Y Y Y O R W W R B R B Y B O What direction? q to quit What direction [right, left, up, down]: ccw G Y Y G W W Y O B Y W R R R G B W O B B Y B O Y G G G R W B W G R G B R B O R O Y Y Y O R W W R B R B Y B O



Part 5

Finally - your simulator will be complete! This assignment will complete the ability to fully rotate your cube.

The basic methods you need for this are in place - the cw() and ccw() inRubikCube. You will need to modify cw() and ccw() inRubikCube to rotate the matching columns or rows of the top, left, right and bottom faces when the front face is rotated. You may need to create other methods in eitherRubikCube orRubikFace to support your efforts.

Sample Run

Y G G G W B O B R G Y Y B W W B W R G B W R O R W G G G B B G R O W G B G W W G Y B B G B O B O B R O W R G What direction? q to quit What direction [right, left, up, down]: cw Y G G G W B B W Y G Y G G R B O W R G B W R O W B G G G B W O R W R G B W W B G Y B B G B O B O B R O W R G What direction? q to quit What direction [right, left, up, down]: ccw Y G G G W B O B R G Y Y B W W B W R G B W R O R W G G G B B G R O W G B G W W G Y B B G B O B O B R O W R G










Step by Step Solution

3.35 Rating (161 Votes )

There are 3 Steps involved in it

Step: 1

Below is the implementation for each part of the Rubiks Cube simulator RubikRunnerjava No changes needed import javautilScanner public class RubikRunn... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advanced Accounting

Authors: Joe Hoyle, Thomas Schaefer, Timothy Doupnik

10th edition

0-07-794127-6, 978-0-07-79412, 978-0077431808

More Books

Students also viewed these Programming questions