I have been running in circles for a few days on this code...I am sure its something simple that I just can't find. This is an assignment and the professor is pretty specific about methods, etc. I will post his instructions, just in case i am interpreting something incorrectly.
I will also post my code thus far.... I finally have the Path class returning the correct
string. I have moved to the Bean Machine class and I need the path to print a string of "LRLLRL" for every ball.... I currently get one continuous string of variables for the amount of balls I drop... but I need them to all be individual strings that I can later search for occurrences of R and L. I just can't get past this part... i can't move on until this gives the right result... Thank you so very much in advance for your time and patience.
***************************instructions*********************************************************
The Problem Statement ‐ Path
Start by creating a class named Path. This class will need to keep up with a single String variable which
will hold a series of characters the will represent the path the ball takes as it falls through the machine.
The only possible characters here are "L" or "R", depending on whether the ball fell to the left or right
when it hit the peg, respectively. For example, in the example shown above, the String would end up
being, "LLRRLLR". Note that because there are 7 levels in this machine, there are exactly 7 characters,
one for each peg that the ball hit.
In addition to the representation of the path, this class will need to provide for the ability to move the
ball to the right and left, to get the full path, and even to fall a specified number of levels. This means it
will need:
A 0‐parameter constructor. Recall that the purpose of the constructor is to initialize the
instance variable(s).
void moveRight() – This method will mark that the ball went to the right when it hit a peg.
void moveLeft() – This method that will mark that the ball went to the left when it hit a
peg.
void fallLevels(int number) – This method simulate and log the ball falling down the
specified number of levels. Remember that at each level there is an equal chance of falling
either right or left (Hint: use Math.random)
String getPath() – This method that will return the String representation of the path.
The Problem Statement ‐ BeanMachine
This class will keep track of the size, or number of levels, of the machine. It will also need to keep track
of the number of balls in each of the bins at the bottom using a simple array.
In addition to these characteristics, this class will also need to provide the ability to simulate dropping a
ball a specified number of times, and the ability to get a description of the number of balls that end up
in each bin. This means it will need:
A 1‐parameter constructor that accepts the number of level in the machine.
void simulateGame(int number) – This method will simulate dropping a ball at the
top of the board the specified number of times
int getBinResult(String) – This method will return the bin number the ball would
land in, if it followed the path provided (Hint: Think about this one carefully. You might want to
try a few examples with paper and pencil so you can see how this works. It may take you longer
than you initially realize)
String getBinDescription() – This method returns a String describing the bins by
including the number of balls in each bin
**********************************************************************************
my code thus far... (after so much revamping and changing LOL)
Current Output....
LLRLLLLRRRLRLLLRRRLLRRRLRLRLRL
Desired output
LLRLL = string x
LRRR = string a ... etc, etc.
Again, thank you in advance for your help....