For my assignment I must write a program that simulates a catapults projectile launch distance and print it to a table. I have no understanding of 2-D arrays even after the class lesson and many other third party resources I have looked at. Can someone please give me tips and help on converting my program to use a 2-D array?
Class 1: tester class
public class CatapultTester{ public static void main(String[] args){ double [] velocity = {20,25,30,35,40,45,50}; double [] degrees = {20,25,30,35,40,45,50}; Catapult vars = new Catapult(velocity,degrees); double [] distance = vars.calcDistance(); System.out.println(" Projectile Distance (feet) "); System.out.printf("%s", "MPH"); for (int i = 0; i < degrees.length; i++){ System.out.printf("%5.0f %1s",degrees[i], "deg"); } System.out.print("\n"); System.out.println("=================================================================="); for(int i = 0; i < distance.length; i++) { System.out.printf( "%2.0f ", velocity[i]); for(int f = 0; f < distance.length; f++) { System.out.printf("%8.1f ", distance[i]); } System.out.printf("\n"); } } } Class 2:
public class Catapult extends CatapultTester { double [] velocity; double [] degrees; Catapult(double[] v, double[] d){ velocity = v; degrees = d; } public double [] calcDistance(){ double [] total = {0,0,0,0,0,0,0}; for (int i = 0; i < degrees.length; i++){ total[i] = (Math.pow(velocity[i]/2.237, 2) * Math.sin(2 * Math.toRadians(degrees[i]))/9.8); } return total; } } Overall I need to take the velocity and angle arrays and combine them into one 2-Dimensional array and they use the method calcDistance() to get a set of values and then use a loop to print them into a table as the output.