DPXJube
12-04-2011, 09:48 PM
Hello all
I've been working on a Mastermind program for a while now and I seem to be getting a problem when I run it.
Methods
public void casualcode()
{
do
{
boomhauer[variable1] = (int)(Math.random() * 6) + 1;
variable1++;
}
while (variable1 <= 3);
for(int bob = 0; bob <= 3; bob++)
{
System.out.println(boomhauer[bob]);
}
if (variable1 == 1) {
hank[variable2] = "Red";
} else if (variable1 == 2) {
hank[variable2] = "Blue";
} else if (variable1 == 3) {
hank[variable2] = "Green";
} else if (variable1 == 4) {
hank[variable2] = "Brown";
} else if (variable1 == 5) {
hank[variable2] = "Yellow";
} else if (variable1 == 6) {
hank[variable2] = "White";
}
for(int carl = 0; carl <= 3; carl++)
{
System.out.println(hank[carl]);
}
}
}
Runner/Main
import java.io.*;
public class Mastermindrunner
{
public static void main(String[] args)
{
String guile; String honda; String viper; int juri; String mature; char yoko;
Mastermind hadoken = new Mastermind();
guile = hadoken.firstinput();
honda = hadoken.helpmenu();
viper = hadoken.difficulty();
hadoken.casualcode();
hadoken.casualintro();
}
}
As you can see, the code is VERY incomplete at the moment, the only difficulty setting that works at the moment is Casual mode.
But anywho, that's not the point.
See this part of the methods?
public void casualcode()
{
do
{
boomhauer[variable1] = (int)(Math.random() * 6) + 1;
variable1++;
}
while (variable1 <= 3);
for(int bob = 0; bob <= 3; bob++)
{
System.out.println(boomhauer[bob]);
}
if (variable1 == 1) {
hank[variable2] = "Red";
} else if (variable1 == 2) {
hank[variable2] = "Blue";
} else if (variable1 == 3) {
hank[variable2] = "Green";
} else if (variable1 == 4) {
hank[variable2] = "Brown";
} else if (variable1 == 5) {
hank[variable2] = "Yellow";
} else if (variable1 == 6) {
hank[variable2] = "White";
}
for(int cool = 0; cool <= 3; cool++)
{
System.out.println(hank[cool]);
}
}
}
What SHOULD be happening is this..
An array of 4 random numbers is generated
THEN another array of 4 strings is generated
The strings will correspond with the random number array (ie if one of the random numbers is 4 then the array will print out Brown)
However when I run the program this is what I get
4
1
1
4
Brown
null
null
null
Does anyone know the reason as to why it prints out as null and only Brown prints out?
I would greatly appreciate any help.
(try to ignore the goofy object and variable names)
I've been working on a Mastermind program for a while now and I seem to be getting a problem when I run it.
Methods
public void casualcode()
{
do
{
boomhauer[variable1] = (int)(Math.random() * 6) + 1;
variable1++;
}
while (variable1 <= 3);
for(int bob = 0; bob <= 3; bob++)
{
System.out.println(boomhauer[bob]);
}
if (variable1 == 1) {
hank[variable2] = "Red";
} else if (variable1 == 2) {
hank[variable2] = "Blue";
} else if (variable1 == 3) {
hank[variable2] = "Green";
} else if (variable1 == 4) {
hank[variable2] = "Brown";
} else if (variable1 == 5) {
hank[variable2] = "Yellow";
} else if (variable1 == 6) {
hank[variable2] = "White";
}
for(int carl = 0; carl <= 3; carl++)
{
System.out.println(hank[carl]);
}
}
}
Runner/Main
import java.io.*;
public class Mastermindrunner
{
public static void main(String[] args)
{
String guile; String honda; String viper; int juri; String mature; char yoko;
Mastermind hadoken = new Mastermind();
guile = hadoken.firstinput();
honda = hadoken.helpmenu();
viper = hadoken.difficulty();
hadoken.casualcode();
hadoken.casualintro();
}
}
As you can see, the code is VERY incomplete at the moment, the only difficulty setting that works at the moment is Casual mode.
But anywho, that's not the point.
See this part of the methods?
public void casualcode()
{
do
{
boomhauer[variable1] = (int)(Math.random() * 6) + 1;
variable1++;
}
while (variable1 <= 3);
for(int bob = 0; bob <= 3; bob++)
{
System.out.println(boomhauer[bob]);
}
if (variable1 == 1) {
hank[variable2] = "Red";
} else if (variable1 == 2) {
hank[variable2] = "Blue";
} else if (variable1 == 3) {
hank[variable2] = "Green";
} else if (variable1 == 4) {
hank[variable2] = "Brown";
} else if (variable1 == 5) {
hank[variable2] = "Yellow";
} else if (variable1 == 6) {
hank[variable2] = "White";
}
for(int cool = 0; cool <= 3; cool++)
{
System.out.println(hank[cool]);
}
}
}
What SHOULD be happening is this..
An array of 4 random numbers is generated
THEN another array of 4 strings is generated
The strings will correspond with the random number array (ie if one of the random numbers is 4 then the array will print out Brown)
However when I run the program this is what I get
4
1
1
4
Brown
null
null
null
Does anyone know the reason as to why it prints out as null and only Brown prints out?
I would greatly appreciate any help.
(try to ignore the goofy object and variable names)