Win a copy of Rust Web Development this week in the Other Languages forum!

Khair Bahir

Greenhorn
+ Follow
since Aug 01, 2011
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
3
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Khair Bahir

Thanks for the reply. I know my way is probably not the easiest or most effective way to do things, but I'm still curious as to why the applet does not run with the tools I've used in my code. Is there a problem with the way I'm trying to display things? If so, what is it? My applet is stuck in the initial starting position and I'm trying to debug that first.
10 years ago
I'm having trouble simulating a race between two competitors. This is your typical race program where you use a random number generator to determine what "moves" the competitors use. As seen in my code below, the track is composed of 50 rectangles, and the filled in rectangle shows the location of each competitor on the track. Some "moves" make the competitor jump 9 squares to the right, or 2 squares back, for example. When I run the applet, only the initial starting position is displayed; the applet doesn't work. I realize it's a lot of code, but what do I need to do to fix my problem? I'm really stuck at this point. Any help is appreciated.

10 years ago
I'm trying to set up a morse code-english converter by prompting the user for morse-->english translation or english--> morse translation, prompting the user to enter the text to be translated, and then finally translating it. So far, I've been able to do english-->morse code translations because that just involves encoding each individual letter. I'm having trouble with morse-->english translations though because that doesn't just involve decoding each individual character. The problem I'm having is I don't want the program to convert each individual dash and period to a letter, but rather a string of dashes and periods to a letter (..-. = f). I also want "|" to separate each word in morse code. For example, if morse code input is "-- -.-- | -. .- -- ." then translated output should be "my name". I implemented this successfully in the stringToMorse() method, but I don't know how I would do it in the stringToEnglish() method. Any ideas are appreciated.

10 years ago
I'm trying to randomly generate a few images from a directory of images, but I have no idea how to do it.

This is what I have without the random image generation component:



I've heard that using a random number generator and/or array can display randomly selected images. Can anyone help me understand how that would work? Thanks.
10 years ago
Hey guys,

This is a snippet of how I'd normally load images (where the images are cards) from the directory "images":



What if I had 52 cards? Is there a better way than to write out every statement?
10 years ago
Thanks for the reply. Unfortunately, I'm not quite sure how to do this. Can you show me how to do this in the context of equating integer input to args.length? Or perhaps direct me to a place to learn more about how I could do it? Thanks.
10 years ago
Hi,

I'm trying to loop through a statement block x number of times, where the user inputs the integer x from the command line. However, the default command line argument is a string, so inputting "3" will cause the statement block to execute only once, as opposed to 3 times. Any ideas?



This is the construct I've been using. I want args.length to be equal to whatever integer I input from the command line.
10 years ago
Thanks very much for your help. I've got it to work.
10 years ago
I made some changes. For some reason I'm getting an output of [i@addbf1 that repeats 25 times and [I@42e816 that also repeats 25 times (not italicized). Why am I getting these weird outputs instead of even and odd numbers? Sorry, I'm still in the process of understanding arrays.
10 years ago

fred rosenberger wrote:you can't just print an array like that. What you really want to do is print each element in the array. it is not too hard to write a method that takes an array as an argument, loops through it, and prints each element, if that is waht you want.



Thanks for pointing that out. What I want is to take those elements, differentiate between the odd and even numbers, and sort those numbers into arrays of their own (an array of odds and an array of evens). I'm doing something fundamentally wrong in the sortEvenOdd() method, but I don't know what it is.
10 years ago
Hello,

So I was able to store 50 random integers in the range of 1-10 in an array (thanks to a previous post). Now, I'm trying to call class methods that will sort the odd and even numbers of the array into arrays of their own. The problem is that I don't know the size of each array because I don't know how many even & odd numbers were in the original array, as the numbers were randomly generated.


I get the following output that repeats for 25 lines:
[I@addbf1
[I@42e816

As you can see, I'm really stumped as to how to extract the even & odd integers of the first array and sort them into separate arrays. My code may look really convoluted. Wrong approach? Fundamental misunderstanding of arrays? Any help is appreciated. Thanks.
10 years ago
Yeah, I know now that casts take higher precedence than multiplication operators, which is why the program just displayed a bunch of zeroes when I omitted a set of parentheses. Thanks for your guys' help.
10 years ago
Hello,

I'm trying to generate 50 random integers between 0 and 10 using a 'for' construct and the 'Math.random()' method. I know how to do this, but I don't know how to store all these integers in an array (one dimension). I really only know how to store integers by manually inputting them into the array. I haven't made much progress and could use some help.

This was my attempt (it doesn't work):



Thanks.
10 years ago
I'm trying to design a program that will display the following:

*****
****
***
**
*

I'm sure there is some way to use loop constructs to make even 100 rows of the previous message, but I'm not sure how.

I was thinking of using a 'for' construct to generate numbers from 5 to 1, and then assigning each number to a certain number of *, but even this I don't know how to do.

Is there a better approach?

Thanks.
10 years ago