So, I'm making a program that calculates the distance given seven velocities and six angles of trajectory. Given the formula to conduct the necessary 42 operations, I must store the results in a two-dimensional array and print the results in a neat and orderly fashion.
I am having confusion on why a particular part of my program is not working. It seems alright to me, however the output is not what I was expecting because it's random and illogical. The error is the output given from the code which results in "Catapult@xxxxx...." where the "x"s represent a random series of letters, numbers, or characters. I'm not sure where they come from and why, so I would like an explanation, and how to fix this problem of mines. The source code is below:
static final int ROWS = 7;
static final int COLS = 6;
public static void main(String[] args)
{
double[] angles = {25.0, 30.0, 35.0, 40.0, 45.0, 50.0};
double[] rads = new double[COLS];
for(int i = 0; i < COLS; i++)
{
rads[i] = Math.toRadians(angles[i]);
}
double[] speeds = {20.0, 25.0, 30.0, 35.0, 40.0, 45.0, 50.0};
Catapult[][] projectile = new Catapult[ROWS][COLS];
for(int a = 0; a < ROWS; a++)
{
for(int b = 0; b < COLS; b++)
{
projectile[a][b] = new Catapult(speeds[a], rads[b]);
}
}
If you were to type System.out.print(projectile[a][b] + " ");
after projectile[a][b] = new Catapult(speeds[a], rads[b]);
in the second for-loop, then it would result in the error described earlier.