ive got most of this figured out. the problem is then when i run, instead of my methods iterating through my array list, they simply reuse the same data set over and over, giving the same results. if anyone can help, it is appreciated.
/**
* Write a description of class CatapultTester here.
*
* @author (your name)
* @version (a version number or a date)
*/
import java.util.*;
public class CatapultTester
{
public static void main(String[] args)
{
ArrayList<Catapult> catapultInfo = new ArrayList<Catapult>();
catapultInfo.add(new Catapult(20, 0.43));
catapultInfo.add(new Catapult(25, 0.52));
catapultInfo.add(new Catapult(30, 0.61));
catapultInfo.add(new Catapult(35, 0.69));
catapultInfo.add(new Catapult(40, 0.78));
catapultInfo.add(new Catapult(45, 0.87));
catapultInfo.add(new Catapult(50, 0.95));
//print header
System.out.println(" Projectile Distance (feet)");
System.out.println(" MPH \t 25 deg \t 30 deg \t 35 deg \t 40 deg \t 45 deg \t 50 deg \t 55 deg");
System.out.println("===============================================================================================================");
for (int counter = 0; counter < catapultInfo.size(); counter++)
{
System.out.printf(" %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f", String.valueOf(catapultInfo.get(counter).distanceFeet) +
String.valueOf(catapultInfo.get(counter).distanceFeet) + String.valueOf(catapultInfo.get(counter).distanceFeet) +
String.valueOf(catapultInfo.get(counter).distanceFeet) + String.valueOf(catapultInfo.get(counter).distanceFeet) +
String.valueOf(catapultInfo.get(counter).distanceFeet) + String.valueOf(catapultInfo.get(counter).distanceFeet) +
String.valueOf(catapultInfo.get(counter).distanceFeet));
}
}
}
/**
* Write a description of class Catapult here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Catapult
{
public double launchSpeed;
public double launchAngle;
public double distance;
public static final double accelerationDueToGravity = 9.8;
public static final double speedFeetFactor = 3.28;
public double distanceFeet;
public Catapult(double speed, double angle)
{
distance = speed * speed * Math.sin(2 * angle) / accelerationDueToGravity;
distanceFeet = distance * speedFeetFactor;
}
public double calcDistanceMeters()
{
return distance;
}
public double calcDistanceFeet()
{
return distanceFeet;
}
}