can anyone help-part2(Tagged code)

Hi,Norm jon,
I am posting a new thread for tagging the code accordingly. Hope this helps out.

1.My ball is not bouncing within the circle i drew.(Within circle 2).It just goes vaguely toward one direction and comes back.I want the ball to bounce randomly.Just like in the game ball and the brick where u have to break the bricks using the ball bouncing randomly.

2.And , i also want to move the triangle according to my direction keys.(Look at the triangle class and the KeyPressed() method).The triangle does move but only once.After that no matter how many times i press the directional key all in vain. I would like to request you to run the code in your locally machine in Eclipse for a better idea of what am asking. You will easily get what m trying to do.

3. And if possible the triangle i made gotta shoot small balls(like bullets from a gun) and when it strikes the bouncing ball, the ball should break up into 2 separate balls.Any idea on how to do this functionality will be of great help.
Hope to c your reply really soon.

This is much easier to read. (I'm actually glad that you didn't include debug code here, although I agree with Norm that they will certainly help you know what's going on at any given point in your code.)

I'm reading it now, notes follow:

- why no constructor for your Ball class? You have setters, and an initBall method that sets up your ball to a default set of values. Ball should have a constructor that takes any values that you expect to be set at startup. You should then create a void constructor to handle your default Ball. This would just call your more elaborate constructor with the default values.
Like this:

Then get rid of initBall, you don't need it. When you make a new BallEntity, without parameters in the constructor, it'll just build you the basic standard default BallEntity. (there are times when you need to initialize an object from another object, but this isn't one of them)

- Ball is just a bag of data. This is okay, but you should wonder what it is that balls do, and why this one doesn't do anything. You might find that there are bits of functionality that you're doing in other places which would be better localized in the BallEntity class. Haven't seen them yet, but I'm still walking through the code.

- Still in Ball: do you expect the width and height to change in the course of the applet? Do you expect the ball to be anything but circular? You can get rid of setters that aren't going to be called, and replace height and width with radius if the ball is a circle. If the ball will change shape in the game, of course, you might want to keep these. Better, though (referring to previous comment) to let the ball change itself. If the ball grows under some circumstances, put in a "grow()" method which figures out what its new size should be and sets itself accordingly. This way you don't have to keep track of the size (or use those getters, also probably not necessary) to deal with the size of the ball in some class. (Imagine a terrible mailroom worker: you bring him a letter, and he asks you how much postage to put on it. You either have to have that written down somewhere, or you ask him, what's the postage on a letter?, and he tells you, and you say, okay, put that much on the letter)

Okay, so we haven't got to your actual problems yet, but there's some things to fix. I'll have more for you shortly, which might even address the problem you asked about.

My problem is that the triangle i am trying to move using directional keys is not working properly

Why is that? Add some debugging statements to see what is happening. There is no magic here. The code is generating numbers different from what you are expecting. If you print out the numbers you will see what is happening and can then work on how to change the code to make it do what you want.
Let me take your hand and show you how to do this. Add the following in the Triangle constructor after the call to super:

This is much easier to read. (I'm actually glad that you didn't include debug code here, although I agree with Norm that they will certainly help you know what's going on at any given point in your code.)

I'm reading it now, notes follow:

- why no constructor for your Ball class? You have setters, and an initBall method that sets up your ball to a default set of values. Ball should have a constructor that takes any values that you expect to be set at startup. You should then create a void constructor to handle your default Ball. This would just call your more elaborate constructor with the default values.
Like this:

Then get rid of initBall, you don't need it. When you make a new BallEntity, without parameters in the constructor, it'll just build you the basic standard default BallEntity. (there are times when you need to initialize an object from another object, but this isn't one of them)

- Ball is just a bag of data. This is okay, but you should wonder what it is that balls do, and why this one doesn't do anything. You might find that there are bits of functionality that you're doing in other places which would be better localized in the BallEntity class. Haven't seen them yet, but I'm still walking through the code.

- Still in Ball: do you expect the width and height to change in the course of the applet? Do you expect the ball to be anything but circular? You can get rid of setters that aren't going to be called, and replace height and width with radius if the ball is a circle. If the ball will change shape in the game, of course, you might want to keep these. Better, though (referring to previous comment) to let the ball change itself. If the ball grows under some circumstances, put in a "grow()" method which figures out what its new size should be and sets itself accordingly. This way you don't have to keep track of the size (or use those getters, also probably not necessary) to deal with the size of the ball in some class. (Imagine a terrible mailroom worker: you bring him a letter, and he asks you how much postage to put on it. You either have to have that written down somewhere, or you ask him, what's the postage on a letter?, and he tells you, and you say, okay, put that much on the letter)

Okay, so we haven't got to your actual problems yet, but there's some things to fix. I'll have more for you shortly, which might even address the problem you asked about.

Hi Jon,
The setters method are there to reposition the ball in d frame(NOT APPLET) after the thread sleep(Code line 170-272).This thread runs to make the ball bounce in the circle randomly much like the brick and ball game where we break the bricks with ball bouncing randomly.But the randomness in the bouncing isn't there.May be a different approach should be applied.You can suggest one .I can try it.

And the other messy part is the keyPressed() method.(code line 139).My Triangle object do move by pressing the directional keys but only once.i think you can figure out the problem as its a very short logic involving only Triangle object and the keyPressed() method.I gotta move the triangle in the frame. Seemed easy but could not go do it.

Okay, continuing on. Your Triangle class is pretty minimal. It creates itself and then there's no way to do anything to it. This may be why it's not moving. Norm's advice is (as usual) good advice. If you want to know what's happening in Triangle, you should ask it to tell you.

Okay, so now I'm looking in your main, and I see a whole lot of code dedicated to moving a ball around. Is this best done by the main class? Or is there a class that's more directly concerned with the ball's position and location?
Incidentally, I don't see any code that's responsible for moving your Triangle. (the code you think is moving it, isn't - what is it really doing?)

Looking at the code for motion, it's obvious why your motion is not random: you have no call to a randomizer. However, that's not your problem. Newtonian mechanics is not random, and that's what you're trying to model, apparently. So don't go bringing in java.util.Random or Math.random - they're not what you need here.
Instead, look at your series of if statements, and run them through by hand. Pick a reasonable set of starting values, and move through the steps you've coded. I think you'll find pretty quickly that you're in a steady cycle, which is what you mean by "not random".
The problem is that your physics allows only for reversing direction.

The fix is not going to be easy - you have to rewrite all of your motion code to reflect the actual bouncing of a ball. In a simplified, frictionless world, that's not so difficult, but pretty much everything you've got is going to have to be replaced. I see no way to salvage this code and make it bounce a ball in the way you want to, particularly not when you're talking about bouncing inside a circle. I don't think this can be done with if statements - there are formulas for this, I don't know off the top of my head what you'd use for a ball moving at (deltzX, deltaY) bouncing off the impact of a circle - possibly you'd figure it as if it were hitting a line tangent to the circle at the point of impact, but I don't know if that's right.
Anyway, I'm sorry, but there's no easy fix for the ball bouncing, given your current code.

I have a 2d matrix with dimension (3, n) called A, I want to calculate the normalization and cross product of two arrays (b,z) (see the code please) for each column (for the first column, then the second one and so on).
the function that I created to find the ...

Write a C program that should create a 10 element array of random integers (0 to 9). The program should total all of the numbers in the odd positions of the array and compare them with the total of the numbers in the even positions of the array and indicate ...