Print Out A Rubik Cube Using A Matrix

Dec 22, 2014

I am trying to print out a rubix cube nicely so that it looks something along the lines of this:

** ** ** R1 R2 R3 ** ** **
** ** ** R4 R5 R6 ** ** **
** ** ** R7 R8 R9 ** ** **
B1 B2 B3 Y1 Y2 Y3 G1 G2 G3
B4 B5 B6 Y4 Y5 Y6 G4 G5 G6
B7 B8 B9 Y7 Y8 Y9 G7 G8 G9
** ** ** O1 O2 O3 ** ** **
** ** ** O4 O5 O6 ** ** **
** ** ** O7 O8 O9 ** ** **
** ** ** W1 W2 W3 ** ** **
** ** ** W4 W5 W6 ** ** **
** ** ** W7 W8 W9 ** ** **

however, when I try to print out the entire cube, I get this:

** ** **
** ** **
** ** **
R1 R2 R3
R4 R5 R6
R7 R8 R9

[code]....

I have found out the area that causes this, my toString, but I want to know if there is something built in or not that will allow me to print it such that I can continue printing it at the same row level as its neighbor, even though I create a new line for each individual column? Here is the code that I try to print out the entire cube:

void printEntireCube(){
for(int row = 0; row < 4; row++){
for(int col = 0; col < 3; col++){
System.out.print(cube[col][row] + " ");
}
System.out.println();
}
}
void createCube(){

[code]....

View Replies


ADVERTISEMENT

Rubik Cube - Aligning Middle Side Color With Bottom Middle Side Color

Jan 16, 2015

I am trying to align the core/middle side color of a cube, index 4, with the bottom middle color of the same side, index 7. (Each side has values 0-8 where 0 - is the top left corner, 1 is the top mid corner, 2 is the top right corner, 3 is the middle left corner, etc).

In addition to lining up those two colors, I am also making sure that the neighbor color of index 7(the color that it is attached), in this case the bottom color, matches with the top core/middle color. I will attach some pictures and a print out to show what I am talking about...

However, in my code when I am trying to align all of these up together, it does not go into the while loop. Each of the loops essentially is trying to get a match of same color with index 4 and 7, as well as making sure that index 7's neighbor color (the bottom color, in this case) matches with the top color.

Here is what I have tried:

private void alignSideColor(){//make the bottom colors neighbor match with a middle side value and rotate it to the top, for the top cross

if(cube.bottom.square[1].charAt(0) == topColor){
while(cube.front.square[7].charAt(0) != frontColor && cube.bottom.square[1].charAt(0) != topColor){
rotateBottomClockwise(1);
System.out.println("Trying to align side color...");

[Code] .....

The print out of the ELSE IF is:
alignment is: W-G and tops: R-R
NOW ITS ALIGNED
even though the sides, index 4 and 7, are NOT aligned with each other

I have also tried the same thing but with out the 2nd condition in each while loop, and although is DOES enter the while loop, it does not perform correctly -- index 4 and 7 WILL have matches colors, but it does not check to see if index 7's neighbor matches with the top color.

Here is how it prints out
** ** ** G7 B6 Y1 ** ** **//this portion is the back of the cube
** ** ** R6 W5 O4 ** ** **
** ** ** R3 W2 O1 ** ** **
B3 G4 Y9 W9 O8 Y7 W3 B4 G9//this portion is the left, top, and right of the cube
B2 G5 R8 W4 R5 Y6 O2 B5 G8
O7 W8 R9 B7 B8 B9 R1 R4 R7
** ** ** O3 O6 O9 ** ** **//this portion is the front of the cube
** ** ** Y2 Y5 Y8 ** ** **
** ** ** B1 G6 W7 ** ** **
** ** ** Y3 Y4 G1 ** ** **//this portion is the bottom the cube
** ** ** R2 O5 G2 ** ** **
** ** ** W1 W6 G3 ** ** **

Here is the cube showing the top, left and front side

Here is the left and bottom side. As you can see index 4, G5 -- yes that is a 5 lol -- does not have the same color as index 7, W8.

I need to rotate the bottom until W8 is aligned with a middle white value. An examples of a neighbor is: W8-R2

View Replies View Related

Checking If Matrix Is Upper Or Lower Triangular Matrix Based On User Input

Dec 5, 2014

java program that will determine if the matrix is a lower or upper triangular matrix. I only need to use java.util.Scanner;.

View Replies View Related

How To Change Value Of Side1 In Cube Object

Apr 8, 2015

I have to write programs using inheritance and got everything working but need to set a value for side1 in the cube class.
 
public class Cube extends ThreeDimensional{
 public Cube(){
super();
}  public double setOneSideofCube(){
//side1 = setOneSideofCube();
return side1;

[code]....

View Replies View Related

Creating A Cube Applet - How To Loop DrawLine

Mar 16, 2014

import java.awt.*;
 public class Exercise5 {
public void paint(Graphics g) {
g.drawRect(30, 50, 50, 50);
g.drawLine(30,50,40,40);
g.drawLine(80,50,90,40);
g.drawLine(40,40,90,40);
g.drawLine(80,100,90,90);
g.drawLine(90,40,90,90);
}
public static void main(String args[]) {
}
}

I got how to create the cube, but how do i loop the drawline? I am supposed to only have one ?

View Replies View Related

Swing/AWT/SWT :: Making A Tetris Clone - How To Get Cube To Visualize In JPanel

Nov 10, 2014

My question is, how do I get my Cube to visualize in the JPanel? I've tried a bunch of add methods but they don't compile. Is there a proper method I can use to add an object to a JPanel?

import javax.swing.*;
import java.awt.Dimension;
import javax.swing.Timer;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.*;

[Code] ....

View Replies View Related

Create A Class Called Dice To Represent SINGLE Cube

Apr 15, 2014

I need to work on this "Dice" program. I've done it twice already. I've also been pouring over examples on here and elsewhere online, but none of them exactly match what I'm doing, as they all say "Pair of Dice".Mine says: "Create a class called Dice to represent a SINGLE cube". It should have a method called roll() that randomly selects a number from 1-6 for the value of the dice."

It has to use java.util.random, not math.java, and it has to have numberShowing:int, roll():int, and main() all in it.The last part reads "Create a test main method for the Dice class that creates a dice and rolls it many times. Can you keep track of how many times a number comes up? Describe how or implement it in the program." I have started at this computer for hours, and read as much info as I can.

View Replies View Related

Write Java Program That Calculates Area And Volume Of Cube?

Sep 10, 2014

Write a Java program that calculates the area and volume of a cube, sphere, cylinder, and regular tetrahedron. Your program should obtain the necessary input for each of the objects from the console and output the input, area, and volume of the object. Use appropriate messages to guide the user of your program.

Here what i did, i am not sure if this is what the assignment want, but this is the best method i could come up with

//Khang Le
import java.util.Scanner;
public class InputAreaVolume {
public static void main(String[] args) {

[Code]......

View Replies View Related

Calculate Area And Volume Of Cube / Sphere / Cylinder And Regular Tetrahedron

Sep 9, 2014

Write a Java program that calculates the area and volume of a cube, sphere, cylinder, and regular tetrahedron. Your program should obtain the necessary input for each of the objects from the console and output the input, area, and volume of the object. Use appropriate messages to guide the user of your program.

View Replies View Related

How To Make Print Employee Button To Print Info Of Other Class

Apr 12, 2014

Basically the class is supposed to have a static variable that keeps track of the number of companies (numberOfCompanies) that have been created and a static method that returns the value of this variable. I need to have a constructor and a method to addEmployee, a method to printCompany, and a toString method. The addEmployee method will check that there is only 1 salesperson, 2 designers, and 4 manufacturing persons at a time and will check that there are no more than 7 employees of the company.

The addEmployee method will return a String indicating what the error is (i.e. "There is already a sales person in this company") or a null if the employee was added. If attempting to name a third company, an error message will be shown. what i have so far but my print company mmethod returns null company class :in which i am obliged to use inputdialog because it says that it cannot return void when i use the showmeassage diaolog.

company class:

import java.util.ArrayList;
import javax.swing.JOptionPane;
public class Company {
private ArrayList<Employees> list ;
private static int numberOfCompanies;

[Code] ....

error message when print button is clicked:

Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: JOptionPane: parentComponent does not have a valid parent
at javax.swing.JOptionPane.createInternalFrame(Unknown Source)
at javax.swing.JOptionPane.showInternalOptionDialog(Unknown Source)
at javax.swing.JOptionPane.showInternalMessageDialog(Unknown Source)

[Code] ......

View Replies View Related

How To Get Each Row Of A Matrix From Input

Apr 24, 2014

Im trying to get the user to input the rows one by one but my input stops after the first. the examples i looked at in my book had this way i used as well. i are my rows and j are my columns. What is the correct way to do it?

import java.util.Scanner;
public class Exercise08_01 {
public static void main(String[] args) {

[Code]....

View Replies View Related

Matrix LL Representation

Aug 1, 2014

Ok I am trying to at this point read in a matrix from a txt file in the format with order of the matrix leading the matrix. Like this :

1
5
2
2 3
5 9
3
3 -2 4
-1 5 2
-3 6 4
4
2 4 5 6
0 3 6 9
0 0 9 8
0 0 0 5
4
2 4 5 6
0 0 0 0
0 0 9 8
0 0 0 5

My code then is supposed to read it in and store it as an Array of singly linked lists. I am having trouble with my code, I am only getting outputs where it is only storing the first line of the txt matrixs like so:

5.0

2.0 3.0
2.0 3.0

3.0 -2.0 4.0
3.0 -2.0 4.0
3.0 -2.0 4.0

2.0 4.0 5.0 6.0
2.0 4.0 5.0 6.0
2.0 4.0 5.0 6.0
2.0 4.0 5.0 6.0

2.0 4.0 5.0 6.0
2.0 4.0 5.0 6.0
2.0 4.0 5.0 6.0
2.0 4.0 5.0 6.0

Is there something obvious in my code that is making it only save the first lines and how can i fix it.

//import java tools
import java.io.*;
import java.util.Scanner;
//Test.java
//See readMe.txt file for implementation instructions
//input: "input.txt"

[code]...

View Replies View Related

Why Code Is Not Printing Matrix And Sum

Feb 28, 2014

why my code is not printing the matrix and sum?

The Java-program Matrix below first asks the user for the number of rows and columns in a matrix. After this the program asks for the values of the elements. Finally, program prints the elements of the matrix and their sum on screen. Your task is to create the missing methods. Check the example print to see how to modify the print. When printing the matrix, values on the same row are separated using tabulator.

Program to complete:

import java.util.Scanner;
public class Matrix {
public static void main(String[] args) {
int rows, columns;
Scanner reader = new Scanner(System.in);
System.out.print("Type in the number of rows: ");

[code]...

Write the missing methods here / Methods are written in the text box below.

Example output

Type in the number of rows: 3
Type in the number of columns: 4
Type in the element 1 of the row 1: 1
Type in the element 2 of the row 1: 2
Type in the element 3 of the row 1: 3
Type in the element 4 of the row 1: 4
Type in the element 1 of the row 2: 5

[code]...

Matrix:

1 2 3 4
5 6 7 8
9 10 11 12

Sum of the elements of the matrix: 78

my code

import java.util.Scanner;
public class apples {
public static void main(String[] args) {
int rows, columns;
Scanner reader = new Scanner(System.in);
System.out.print("Type in the number of rows: ");

[code]...

View Replies View Related

Create A Matrix Of JTextFields?

Nov 16, 2014

I am making a Sudoku game and creating a matrix of JTextFields. However I am getting the following errors

Exception in thread "main" java.lang.NullPointerException
at SudokuView.board(SudokuView.java:30)
at SudokuView.<init>(SudokuView.java:18)
at SudokuMain.main(SudokuMain.java:5)

I know the problem is with this code

box[i][j] = new JTextField();
panel.add(box[i][j]);

I know this because when I do this:

panel.add(new JTextField());

It works. However it puzzles me why it is not working.

Whole Code:

import java.awt.GridLayout;
import javax.swing.*;
 public class SudokuView {
 JFrame frame;
JPanel panelBoard;
JTextField[][] box;
int row=10; int col=10;
 SudokuView(){
frame = new JFrame("Play Sudoku GOOD LUCK");

[code]....

View Replies View Related

Getting The Index Of A Matrix Of Buttons

Dec 7, 2014

I am attempting to get the x and y coordinate of a matrix of buttons. I have googled my way to failure and read the docs and I think I am traveling of track.

Below is where I create a matrix of buttons via Swing

public class View extends Mybuttons{
 private static final long serialVersionUID = 1L;
JFrame frame;
JPanel matrixPanel, optionsPanel;
Mybuttons[][] matrixBtn;

Later in this class:

JPanel matrixPan(){
matrixBtn = new Mybuttons[25][25];
JPanel panel = new JPanel();
panel.setSize(550,550);
panel.setLayout(new GridLayout(25,25));
//creating a 25x25 matrix of buttons

[Code]...

In the controller class I am trying to get the index of each button in the getUnvisitedChildNode method. I need to do this so I can search the buttons around the button passed to it and check if they are been visited yet. Below getUnvisitedChildNode you will be bfs (breadth first search).

private Mybuttons getUnvisitedChildNode(Mybuttons b){
//example of some of the things I have tried
int x= Mybuttons.getComponentAt(b);
int y= Mybuttons.indexOf(b);
int j=0;
return b;
}

[Code]...

View Replies View Related

Checking Correctness In A Matrix

Nov 21, 2014

I have a programming assignment in which I have to make a program which loads a crossword from a Properties file and then, when the user press a button, the program checks if the letters the user has typed in the interface are the same as in the correct matrix. If all the letters from a word are correct, the program must paint every letter of the word green.

I'm using two matrix, one that is called "mundo" (I 'm from Latin America) , which has the correct letter for each box. The other one is a JtextField matrix which ='ve created using a Gridllayout. I called this one crucigrama (crossword in Spanish)

This is the code I wrote to validate: So you can understand, here is a translation:

numero = number
fila = row
column = columna
bien - a boolean I used to check if the letter I've checked before are the same as the correct ones
.darLetra() - returns a string with the correct letter

[Code] .....

View Replies View Related

Convert String To Matrix?

Mar 8, 2014

I have string abcdef.I need to convert that string into 2 dimensional matrix.For each 2 characters in the string will be a matrix.For instance:

String: abcdef
Matrix will be: [a b],[c d],[e f]

How to do that in java?

View Replies View Related

How To Swap Matrix From Index

Jan 2, 2015

so I have this matrix

1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16

If the user for example enter the number 2 for index I need to swap the matrix from this index two lines with two line so this is the result what I need

1 2 5 6
3 4 7 8
9 10 13 14
11 12 15 16

View Replies View Related

Create Square Matrix That Has Min And Max Value

May 10, 2015

I have to create a square matrix that has a min and max value as well as a size value which is given a integer value in the main method. The matrix has to be filled with random values. Also I have to add that matrix to another one in an addMatrix method and I have to subtract both in a subMatrix method. These are the requirements:

Methods:
Constructor() - receives the row and col size for myMatrix and a max and min values for range of random fill values for the matrix.
RandFill() - fills matrices with random numbers
addMatrix() - receives a matrix object. adds its myMatrix with the received object's myMatrix. The result is placed in this object's myResultMatrix.
subMatrix() - subtracts both matrices

I typed up this code but I'm not sure about some parts of it and I would creating min and max values in the Random method and in the main printing the separate 2 matrices and adding and subtracting them:

import java.util.*;
public class SquareMatrix2 {
public int size;
public int myMatrix [][];
public int myResultMatrix;
public int [][] ResultStatus;

[Code] ....

View Replies View Related

Diamond Matrix Program?

Oct 11, 2014

i want solution to my program

View Replies View Related

Two Threads - One Will Print Odd And Other Will Print Even Numbers In Sequence

Jul 25, 2014

I want to create two thread one thread will print odd number and another thread will print even number. but the number should be in a sequence like

1 2 3 4 5 6 7 8 9 10

View Replies View Related

Adding Rows And Columns In A Matrix?

Apr 16, 2015

I have a 5x5 array of which I read from an external file and I am supposed to print out the original matrix and then add up each row and column, proceeding to store them into the sixth positions in my matrix. After that I print out the new matrix.

For example this just using a 2 by 2,

Original
1 2 3 4 5
1 2 3 4 5
New 3 by 3
1 2 3 4 5 15
1 2 3 4 5 15
2 4 6 8 10 30

I am confused as to how to isolate rows and print them out. I know how to add the entire matrix up but isolation is my issue.

Here is what I have including how to read the matrix and the sum of the whole thing

import java.io.*;
import java.util.*; 
public class prog470cAddingRandC {
public static void main (String [] args) {
//read the file
Scanner inFile=null;

[code].....

View Replies View Related

How To Find Longest Path In A Matrix

Feb 18, 2015

I have some N*M matrix or N*N matrx , and there's a "worm" that can start from any index in the first column, or, any index in the first row. i need to choose the longest worm that satisfying this :

The index that comes after the index before him must be greater then 1. and i must use recursion, also for helper methods. no loops at all. that's it. i'm having a problem to find the longest worm in the matrix.

My idea was to create an helper array and assign to the array indexes a variable that will count the steps of the worm and finally assigns in to the helper array index. then i used findMax method to find the max value in an index. and thats will be the longest worm. i wrote a lot of code so i wont put it here. i will say that i'm close. if the longest worm is 6 i get in my output 7.

View Replies View Related

Get Matrix1 And Matrix2 To Add Up To Create A Third Matrix?

May 2, 2014

I'm trying to get my matrix1 and matrix2 to add up to create a third matrix, I've gotten that down, but now I'm just having some trouble getting it to print out the matrix1, matrix2 and then the final matrix3 or the result matrix?

import java.util.Scanner;
public class Exercise_7_5{
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.print("Enter Matrix 1: ");
double[][] matrix1 = new double [3][3];

[code]....

View Replies View Related

List Particular Row In Matrix Should Be Displayed Using For Loop

Apr 3, 2015

Code in java in which if i want to list particular row in matrix it should be displayed using for loop.

For example in 3 X 3 matrix:

1 2 3
1 1 1
1 0 1

If i want to see only 1st row i.e. 1 2 3 then how to do i do this ?

View Replies View Related

Sparse Matrix Addition And Multiplication

Nov 4, 2014

Code for sparse matrix addition and Multiplication...

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved