Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro SQL Server Wait Statistics

Authors: Enrico Van De Laar

1st Edition

1484211391, 9781484211397

More Books

Students also viewed these Databases questions

Question

4. Does cultural aptitude impact ones emotional intelligence?

Answered: 1 week ago

Question

7. Do the organizations social activities reflect diversity?

Answered: 1 week ago