Question: I can't figure out how to change my code to write info in from a text file for the input. I'll post the context of

I can't figure out how to change my code to write info in from a text file for the input. I'll post the context of the problem I am working on and the code I have finished so far.

The program will create a Catapult object that will create a searchable matrix of trajectories for the given speeds and angles. The object should store these values in a 2D array. Given a target range of minimum and maximum distances, representing the near and far castle walls, the program should search the calculated trajectories and return a list of speed and angle combinations that can be used by your team to successfully launch the catapult. The output should be in an easy to read human readable format. If there are no speed and angle pairs in the current set that will accomplish the goal in the current matrix, the program should also graciously tell the users that they do not have a viable launch. The program will have a number of potential sets of speeds and angles. The program should be able to run the simulation on as many times as indicated by the use. Input will be done from a text file rather than keyboard input.

The program will take input from a text file containing the following information on each line:

Number of sets

Number of speeds, followed by a list of speeds

Number of angles, followed by a list of angles

Minimum trajectory

Maximum trajectory

**speeds, angles, maximum and minimum repeated for the specified number of sets

public class CatapultTester {
public static void main(String[] args) {
Catapult[][] catapults = new Catapult[7][7];
int speed;
for(int row = 0; row < catapults.length; row++) {
speed = 20 + 5 * row;
for(int column = 0; column
{
catapults[row][column] = new Catapult(speed, 25 + 5 * column);
}
}
System.out.println(" Projectile Distance (feet) ");
System.out.println("MPH 25 Deg 30 Deg 35 Deg 40 Deg 45 Deg 50 Deg 55 Deg ");
System.out.println();
System.out.println("======================================================================");
for (Catapult[] catapult : catapults) {
System.out.printf("%2.0f ", catapult[0].getVelocity());
for (int column = 0; column < catapults.length; column++) {
catapult[column].calcDistance();
System.out.printf("%8.1f ", catapult[column].getDistance());
}
System.out.printf(" ");
}
}

}

public class Catapult {
private double velocity, degrees, distance;
public Catapult(double v, double deg) {
velocity = v;
degrees = deg;
}
public double getVelocity(){
return velocity;
}
public double getDegrees(){
return degrees;
}
public double getDistance(){
return distance;
}
public void calcDistance(){
distance = (Math.pow(velocity, 2) * Math.sin( 2 * Math.toRadians(degrees)) / 9.8);
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!