Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Background The belligerent country of Kablamistan has launched an inter-continental ballistic missile towards a country 8000km away which threatens to destroy the peaceful Goners who

Background

The belligerent country of Kablamistan has launched an inter-continental ballistic missile towards a country 8000km away which threatens to destroy the peaceful Goners who live there.

Fortunately the United Nations has anticipated this possibility and, out of concern for the citizens of Goneria, has placed a high-powered laser at the midpoint between the site of the missile's launch (Launchtown, Kablamistan) and the target (Doomsville, Goneria). The laser is capable of destroying the missile in mid-air even at its highest point of 20km above the Earth.

Unfortunately the laser's guidance system got fried when the soldier monitoring the system blew its fuse when trying to cook a pop-tart with the laser and no replacement component could be found. Given the military's well known policy of awarding contracts to the lowest bidder, you've been given the job of developing software to upload into the 80286 computer that will be used to drive the laser! For free!

Also unfortunately, the missile is shielded against lasers and will need to be hit multiple times before being destroyed.

The technical specifications are as follows:

The missile

o is fired towards Doomsville at 12:30PM, i.e. at lunchtime in Launchtown!

o flies an elliptical path (with a major radius of 4000km and a minor radius of 20km) which is 7998km long. And

o travels each of the 180 x 1 segments in which it can be targeted by the laser in 7.405s.

The laser

o is 4000km between Launchtown and Doomsville directly below the path of the missile;

o requires 15.737s to charge before it may be fired;

o moves in 1 increments where 0 is along the ground to Launchtown, 90 is straight up, and 180 is along the ground to Doomsville;

o requires 3.61s to move 1 (and starts perpendicular to the ground, i.e. at 90);

o should only be fired at degrees in the range 1-179;

o may move while being charged; and

o fires instantly for an infinite distance.

missile on its elliptical path is the coordinate (x,y) where x=4000*Math.cos(r) and y=20*Math.sin(r). r is the value t converted to radians and the conversion can be done with a built-in method: r=Math.toRadians(t);

If the missile will be at this coordinate at the time the laser is aiming there then this is a firing solution. Firing solutions consist of:

the time the laser should be fired;

the degree at which the laser should be aimed; and

the resulting coordinate at which impact with the missile would occur.

Program specification

You need to give a Java program to calculate and display all possible firing solutions. These should be found from the greatest distance from Doomsville to the least distance from Doomsville with the previous firing solution as the starting point for the next.

Your solution should comprise the following files:

TimeInterface.java and Time.java the Time ADT as used in lectures and tutorials, extended with a method to add seconds to an existing time. The heading for this additional function should be:

void addSeconds(double s);

Only the whole number portion of the double value should be added to the time object;

FiringSolutionInterface.java and FiringSolution.java the specification and implementation (respectively) of a firing solution. A firing solution should be implemented as a class with instance variables which consist of:

o the time the laser should be fired (as a Time value);

o the degree at which the laser should be aimed (as an int); and

o the resulting coordinate at which impact with the missile would occur (as two double fields, x and y).

and the operations should include a getter and setter for each field; and

AssigOne222.java the file which contains the main() method and other functions which implement the required task. (There is no need to sub-divide main() into additional methods.)

A starting point is available on MyLO for you to download. You should give all the required files. You may need nextLine() and nextInt() from java.util.Scanner, print() and println() from java.lang.System, compareTo() and charAt() from java.lang.String, valueOf() from java.lang.Integer, and format() from java.text.DecimalFormat. You will also need to use if and if-else statements, and for and while loops.

An example of the program's output is shown below:

At time 12:33:42 PM, fire at 30 degrees to impact missile at (3464.102, 10.000)

At time 12:34:04 PM, fire at 33 degrees to impact missile at (3354.682, 10.893)

At time 12:34:26 PM, fire at 36 degrees to impact missile at (3236.068, 11.756)

At time 12:34:48 PM, fire at 39 degrees to impact missile at (3108.584, 12.586)

At time 12:35:11 PM, fire at 42 degrees to impact missile at (2972.579, 13.383)

At time 12:35:33 PM, fire at 45 degrees to impact missile at (2828.427, 14.142)

At time 12:35:55 PM, fire at 48 degrees to impact missile at (2676.522, 14.863)

At time 12:36:17 PM, fire at 51 degrees to impact missile at (2517.282, 15.543)

At time 12:36:39 PM, fire at 54 degrees to impact missile at (2351.141, 16.180)

At time 12:37:02 PM, fire at 57 degrees to impact missile at (2178.556, 16.773)

At time 12:37:24 PM, fire at 60 degrees to impact missile at (2000.000, 17.321)

At time 12:37:46 PM, fire at 63 degrees to impact missile at (1815.962, 17.820)

At time 12:38:08 PM, fire at 66 degrees to impact missile at (1626.947, 18.271)

At time 12:38:30 PM, fire at 69 degrees to impact missile at (1433.472, 18.672)

At time 12:38:53 PM, fire at 72 degrees to impact missile at (1236.068, 19.021)

At time 12:39:15 PM, fire at 75 degrees to impact missile at (1035.276, 19.319)

At time 12:39:37 PM, fire at 78 degrees to impact missile at (831.647, 19.563)

At time 12:39:59 PM, fire at 81 degrees to impact missile at (625.738, 19.754)

At time 12:40:22 PM, fire at 84 degrees to impact missile at (418.114, 19.890)

At time 12:40:44 PM, fire at 87 degrees to impact missile at (209.344, 19.973)

At time 12:41:06 PM, fire at 90 degrees to impact missile at (0.000, 20.000)

At time 12:41:28 PM, fire at 93 degrees to impact missile at (-209.344, 19.973)

At time 12:41:50 PM, fire at 96 degrees to impact missile at (-418.114, 19.890)

At time 12:42:13 PM, fire at 99 degrees to impact missile at (-625.738, 19.754)

At time 12:42:35 PM, fire at 102 degrees to impact missile at (-831.647, 19.563)

At time 12:42:57 PM, fire at 105 degrees to impact missile at (-1035.276, 19.319)

At time 12:43:19 PM, fire at 108 degrees to impact missile at (-1236.068, 19.021)

At time 12:43:41 PM, fire at 111 degrees to impact missile at (-1433.472, 18.672)

At time 12:44:04 PM, fire at 114 degrees to impact missile at (-1626.947, 18.271)

At time 12:44:26 PM, fire at 117 degrees to impact missile at (-1815.962, 17.820)

At time 12:44:48 PM, fire at 120 degrees to impact missile at (-2000.000, 17.321)

At time 12:45:10 PM, fire at 123 degrees to impact missile at (-2178.556, 16.773)

At time 12:45:33 PM, fire at 126 degrees to impact missile at (-2351.141, 16.180)

At time 12:45:55 PM, fire at 129 degrees to impact missile at (-2517.282, 15.543)

At time 12:46:17 PM, fire at 132 degrees to impact missile at (-2676.522, 14.863)

At time 12:46:39 PM, fire at 135 degrees to impact missile at (-2828.427, 14.142)

At time 12:47:01 PM, fire at 138 degrees to impact missile at (-2972.579, 13.383)

At time 12:47:24 PM, fire at 141 degrees to impact missile at (-3108.584, 12.586)

At time 12:47:46 PM, fire at 144 degrees to impact missile at (-3236.068, 11.756)

At time 12:48:08 PM, fire at 147 degrees to impact missile at (-3354.682, 10.893)

At time 12:48:30 PM, fire at 150 degrees to impact missile at (-3464.102, 10.000)

At time 12:48:52 PM, fire at 153 degrees to impact missile at (-3564.026, 9.080)

At time 12:49:15 PM, fire at 156 degrees to impact missile at (-3654.182, 8.135)

At time 12:49:37 PM, fire at 159 degrees to impact missile at (-3734.322, 7.167)

At time 12:49:59 PM, fire at 162 degrees to impact missile at (-3804.226, 6.180)

At time 12:50:21 PM, fire at 165 degrees to impact missile at (-3863.703, 5.176)

At time 12:50:44 PM, fire at 168 degrees to impact missile at (-3912.590, 4.158)

At time 12:51:06 PM, fire at 171 degrees to impact missile at (-3950.753, 3.129)

At time 12:51:28 PM, fire at 174 degrees to impact missile at (-3978.088, 2.091)

At time 12:51:50 PM, fire at 177 degrees to impact missile at (-3994.518, 1.047)

Algorithm

AssigOne222.java could implement the following algorithm:

o setting up the launch time

o iterating through each position (degree) of the missile from Launchtown to Doomsville and for each

repeating the following steps until a solution is found or it is determined there are no solutions

calculating how the laser would need to move to get there

calculating how the missile would need to move to get there

determining how many seconds the movement of each item would take and, if the laser can get there no later than the missile o determine the (x,y) coordinate of impact and the time

o give a firing solution of these values

o display the time and firing solution (you can make use of the defined DecimalFormat objects to format the output of Time and FiringSolution objects)

otherwise

o moving the missile to the next location (degree)

Program Style

Your program should follow the following coding conventions:

final variable identifiers should be used as much as possible, should be written all in upper case and should be declared before all other variables

variable identifiers should start with a lower case letter

every if and if-else statement should have a block of code (i.e. collections of lines surrounded by { and }) for both the if part and the else part (if used)

every do, for, and while loop should have a block of code (i.e. {}s)

the keyword continue should not be used

the keyword break should only be used as part of a switch statement

opening and closing braces of a block should be aligned

all code within a block should be aligned and indented 1 tab stop (or 4 spaces) from the braces marking this block

instance variables should be used sparingly with parameter lists used to pass information in and out of functions

local variables (excluding loop counters) should only be declared at the beginning of methods (either as parameters or otherwise)

commenting:

***************I need a help to complete below coding*****************

** * Assignment 1 * @version <> * * Split <<50:50 or change!>> */

public class AssigOne222 { public static void main(String []args) { COMPLETE ME! } }

Step by Step Solution

3.38 Rating (151 Votes )

There are 3 Steps involved in it

Step: 1

Override public void setYdouble y t... 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

Applied Statistics For Public And Nonprofit Administration

Authors: Kenneth J. Meier, Jeffrey L. Brudney, John Bohte

8th Edition

978-1111342807, 1111342806

More Books

Students also viewed these Programming questions