Bert Wilkinson

Ranch Hand
+ Follow
since Oct 28, 2009
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Bert Wilkinson

Ok...you're moving forward....but your code still needs some serious first aid.

A couple things:

Your logic on your if/else if blocks looks faulty. You want to do some set of things if the user enters a "2"...so why are you using the not "!" operator?

maybe something like



also, you are re-declaring your variable userChoiceAsString inside of each logical segment, so that it is only visible inside that code block. I don't think you want to do that.

and, to convert your strings to Integers, easiest way is:



you will need to do something like that when you get your user's guess.

and as a simple troubleshooting tool, put some print statements in and then comment them out later such as:

System.out.println("evaluating the addition portion!");

13 years ago
Hello Christine.

A couple points/questions:

1. try to use code tags when you post. It makes the posting MUCH easier to read. After you paste your code in, and while it is still "selected" hit the "code button".

2. When you say "you are having trouble with user input" can you be more specific?

3. I think it is most common/easiest to use the Scanner class to read from keyboard. You are using InputReader, which is a not a part of the standard Java API....Do you have documentation and/or examples for it?

13 years ago
I don't think there is a Java Class that supports a key - key relationship like you want. You could force this, as you mentioned using the methods in either HashMap or Hashtable, but it wouldn't be pretty....some kind of mess of contains()...etc.

I think I would either just maintain 2 HashMaps (one in each direction)...or just make up my own Class that utilized 2 HashMaps to store your data



I'm not real excited about this solution....and it seems like too much work for only a dozen or so entries...hmmm.
13 years ago
Agree w/Ernest. You are on the right track. In general, when considering whether or not to make start splitting you code into multiple classes, I think most usually consider:

1. Readability and organization. A couple clearly written classes is usually much clearer (and easier to troubleshoot) than 1 "mega class."

2. Portability/extensibility! Maybe in the future you might develop another game that can use your Player class, or you might refine your Lottery game by extending it with some embellishments.

So, then the challenge becomes how to exchange necessary information (like the Player's guess) between classes. If you are hung up by Ernest's suggestion, you need to spend a bit of time looking at INSTANCE VARIABLES and GETTER and SETTER methods. Your main (executable) class will need to pull information from one class and send it to another class using these concepts. All introductory Java texts (and many online tutorials) have great coverage of this basic concept.

Good luck!
13 years ago

Rob Prime wrote:Thank you so much for completely ignoring my post.



Lighten up.... He's trying the first idea presented.
13 years ago
Well, I think you have a couple problems that you've brought up:

1. your treating your list as "line separated values" not comma separated...because you are treating each line as a string data element. If that is truly what you want to do (which is doubtful) and all you want to do is print it out like that, do as Rob suggested and just iterate over the array with a for loop and print each value on a new line.

2. If your numbers are truly independent values, your structure needs to change. You can't make a 2-dimensional array list, so your options are either:

a. capture each value individually, and use modular arithmetic on the ArrayList to index into the correct position or for printing.

b. use nested ArrayLists as in:



You probably want to do something like (b.) above. In that example, you have an array of patients....each patient has an array of "data values". And you're treating your list of numbers as independent values instead of as a String.
13 years ago
That was the essence of the 2nd hint...that's clearly stated in the javadoc for set().
13 years ago
Step 1 in almost any troubleshooting:

"when in doubt, print it out..."

try adding the following lines of code, your mistake should bubble up quickly:


2nd hint: take a look at the javadoc for the Calendar.set() method.


13 years ago
oops. Missed that!

Got carried away with the claims of bad output when the code doesn't even compile....harrumph.
13 years ago
Aside from some minor formatting and style issues, your code looks correct.

What's happening when you execute it and put in different values? Your testScore variables are independent for each student object that you create (inside the student object), so there shouldn't be any problem with that. As far as the average, there is no "counter" it just returns a computation based on the variables that are, again, independent from other students within your student object. I don't see any showstoppers on first pass... ???
13 years ago
Yo Dinah.

you can't execute a switch statement on a String.

Take a look at this link:

http://java.sun.com/docs/books/tutorial/java/nutsandbolts/switch.html
13 years ago
This method has some hope....but it's not going to work. You're looping through the deck within a loop of the deck....so you're probably getting some crazy answers on this. You need to rethink this and think about all the possible cases. What will you do if you have 2 aces in one hand?

Maybe rephrasing that question will lead you in the right direction: If you knew after going through your hand that you had 2 aces, how would that affect your summation?

good luck. And remember: You'll learn more and get better responses if you post the results of executing your code.
13 years ago
It looks like your instructions for the assignment are in the javadoc....

So, with that in mind, your shuffle method looks like it will do some shuffling, but it is not doing what the javadoc says it should. You are looping through the entire deck TIMES_TO_SHUFFLE times vice doing that many "swaps" within the deck. Hopefully that's clear and gives you some direction on where you need to tweak your code.

After you think you are close, you can put a println statement in there to compare the deck before and after a "shuffle" is called to convince yourself something is happening.
13 years ago
Maybe this is more clear:

You calculate the variable "out" but never use it. That is likely what the compiler is wanking about. Your code is still legit and will compile / run.

In your assertEquals statement, use the "out" variable you calculated instead of calling the sphereSurface method again.

as a minor note....If you're only testing to accuracy of your method to within .001, you can lop off a bunch of digits in your expected value.

14 years ago
Well, if you're doing this for a class, there should be some text examples of how to make class methods....it's an early concept...so you might be missing some key knowledge.

You already have the code... you just need to rearrange a bit.

your final answer will have a "main method" to get things started and then other methods to do the subtask that are outside the main method. A variable that is accessible to all of these methods is a "class variable" or "instance variable" of your class, and you'll need one of those to retain info (at this level)

this will snap right into place after you do a little work on figuring out class methods.
14 years ago