Win a copy of Microservices Testing (Live Project) this week in the Spring forum!

# Kevin Behr

Greenhorn
since Jun 29, 2006
Cows and Likes
Cows
0
In last 30 days
0
Total given
0
Likes
0
0
Total given
0
Given in last 30 days
0
Scavenger Hunt
Ranch Hand Scavenger Hunt
Greenhorn Scavenger Hunt

## Recent posts by Kevin Behr

Hey guys,

Thanks for all of your replies! I greatly appreciate it.

Ganesh: Nice implementation, but unfortunately I can't use it. Campbell is right in that I have to work out the algorithm. The reason being is that I am taking a "Formal Methods and Models" class, in which we derive programs (mathematically). I'm working backwards to understand the problem more (and because I'm awful at math!).

Rob, you were right, by changing the < to a <= in the second for loop, the 11 appeared. I test a couple more sets, and things seem to be working well!

Now that I understand what the program should look like, I have to derive it from a loop invariant that was given to me

Thanks again!
13 years ago
Hey everyone,

Given a sorted array (of ints), I need to change the array so that any integer that appears only once will appear at the beginning of the SAME array, and still in a sorted order. Also, the program's running time should be proportional to the array (so I cannot have one loop nested inside another loop).

I have done this. However, there is some flaw in my code such that for the following array:

{0,2,2,3,3,7,9,11,11}

My output is:

{0,2,4,7,9}

So, it's not including the last 11. In my attempts to fix this, I have been recieving some out-of-bounds errors. I think I've just been looking at the code for too long. Can anyone see the problem? Here is my code:

Thanks!
13 years ago
Hey everyone,

I am writing a program that reads in sentences from a text file, and then converts those sentences (a StringBuffer) to a String. Then, I convert that String into a character array. Once I do that, I want to do the following...

Right now, the following code will insert a '^' at the MAXPOS (say, 25) position in the character array, IF that MAXPOS position is a blank space ' '. Each time MAXPOS is reached, the count will reset to 0 and will again search the array to MAXPOS...this happens until the end of the character array.

Here is what I cannot do, and was wondering if someone can help me...If the MAXPOS position is not a blank space, I want to insert a '^' to the nearest blank space BEFORE the MAXPOS occurs (So, the blank space before the current word).

Does anyone have any ideas? I'd greatly appreciate it. I'm not restricted to using a character array - analyzing the String directly is fine, too.

Thanks!
13 years ago
Hey all,

I am going to write a program that will accept:

-a quantity (i.e. 0, 17, many, twelve, etc.)
-a string (apple, apples, cat, goose, etc.)

The program will determine (based upon the quantity) whether the string should be singular or plural. So if I enter '17', 'apple', it will correct it to '17 apples'.

I don't want to go into too much detail about how I plan to go about this, but basically I am going to have two text files, or two "dictionaries" - one for quantities, and one for strings.

Here is what the dictionary may look like:

So the string dictionary will contain the following types: Regular, Irregular, and Uncountable.

The quantity dictionary will contain the following types: None, One, and Many.

So when the user inputs the quantity, it will search the quantity dictionary and determine of what "type" it is (none, one, or many). Based upon the result. Then, the string dictionary will searched with the provided string - it will choose either the singular or the plural based upon the quantity "type".

If either the quantity or the string (or both) is not found in the corresponding dictionaries, the program will have the functionality to insert the values into whichever dictionary.

I hope that all made sense - I just want to see what you guys think of my approach. It has to be done in Java, and I have a week to do it - it's not supposed to be too complex.

Thanks!
13 years ago
Oh, got it! Thanks!
14 years ago
So for each button, would I call MyColorButton();?

I tried that, and it says that it cannot find the method...
14 years ago
Thanks alot! This will go to good use. I will try it out now.
14 years ago
Thanks for all your help guys, I really am learning a great deal by it.

Campbell, I get what you are saying. I have 32 buttons, so I want to set up a method ColorChanger() where I will put my code, then can I just do this for each button...?

Is this possible since all my buttons have different names?
(gboard_row1_btn1.setBackground(colors[index])

Also, the only other thing I am unclear on is initializing the index. I have to initialize it to be 0. So each time the button is pressed, won't it re-initialize to 0?

Thanks!
[ July 09, 2008: Message edited by: Kevin Behr ]
14 years ago
Ok, yes I found it easier too. Thanks alot.
14 years ago
Hey guys,

Similar to my prior post...

I have the following code

What I need to do is, each time the Button is clicked, change the background color of the button (so first its red, then orange, then yellow, etc.)

So I need a way to go through the array on each click, and then repeat. But I can't seem to get my loops right...

Does anyone know a better way?
14 years ago
One more thing - I have each "set" of JButton's and the Guess Button in it's own JPanel - just to keep them grouped together. Should I take them out? Are there advantages/disadvantages?

Thanks!
14 years ago
Great, thanks alot! I'll use the JButtons instead.
14 years ago
Hey all,

So I created a text-based version of the game mastermind. If you are not familiar with it, here is a link to a pre-existing java game:

http://www.irt.org/games/js/mind/

What I want to do now, is to develop a GUI for it. So I downloaded NetBeans, and created a UI for it. Before I start what I believe will be a difficult task (adding functionality to the UI - I have never done this before), I have a question or two:

First, here is the UI that I have created:

Now, the white boxes that you see are text boxes...

First question: Is it possible to click on a text box and, each time I click on it, the background color changes (looping through six colors)?

Second question: Is there a way to disable a Panel? Or, if not, to disable text boxes and buttons?

Third question: If I cannot achieve that which is presented in the first question, I will simply have the user type in the first letter of each of the six colors, i.e. R,O,Y,G,B,P into the text boxes. Can I limit the length of the text boxes to 1 character?

Thanks for your help guys, I feel like this will be tough...
14 years ago
Hello, I have two arrays: useCode[] and board[][].

Each array contains four colors (for the 2D array (board), each row contains four colors).

What I am looking to do is to compare the two arrays. I am looking to increment the integer variable 'none' for every color that exists in
board[][], but does not exist in useCode[].

Does anyone have any suggestions how I might accomplish this? So far, this is what I have:

I count how many times each color appears. But, since there are a total of six colors, and each array can only has four colors, I need a way to compare the two arrays...

I hope that makes sense, thanks for any help!
14 years ago
That helps yes, from that I have created the following case statement:

Now, If I can get a tally of each color of each array (board[][] and useCode), then I should be able to compare the tallies - for every tally from each board that is not equal to each other, i know i will have to place an "o" in my clues[] array - but then i run into a similar problem if the tallies are equal - again, it could result in either a "B" or a "W"...ahhh! Is there a better way you know of for trying to distinguish the cases (using the case statement?)
15 years ago