CSC 213 — Programming Fundamentals

Review Part 01 - Missile Defense

You're working for the US defense department on a missile defense program. The goal is to create a program that will shoot down any missile that comes within 30 miles of the White House. Unfortunately, the missile tracking reports you receive come from your allies in France who are reporting everything in kilometers.

You will write a program that will take a missile distance given in kilometers, convert it to miles, and decide whether or not to launch the interceptor.

The program will then ask you if there are more missiles in the air. If so, repeat the program. If not, end the program with a message of peace and congratulations.

Assignment

The following are example runs of the program. User input is underlined.

Super Secret Missile Defense Program

        Enter the distance of the missile: _25_
        Distance is 15.53 miles, fire!

Are there more missiles incoming? _N_
Congratulations! Peace on Earth!
Super Secret Missile Defense Program

        Enter the distance of the missile: _100.7_
        Distance is 62.57 miles, hold your fire.

Are there more missiles incoming? _Y_

        Enter the distance of the missile: _20_
        Distance is 12.43 miles, fire!

Are there more missiles incoming? _N_
Congratulations! Peace on Earth!

Requirements

float getMissileDistance() {
    // ...
}

float convertKilometersToMiles(float km) {
    // ...
}

boolean shouldFireMissile(float distance) {
    // ...
}

Hints

class Main extends ConsoleProgram {

    public void run() {

    }

    public static void main(String[] args) {
        new Main().start(args);
    }
}

Stretch Goals:

If you get all of the above working, try the following stretch goals:

  1. The army has developed a new, ultra missile. This missile is much faster than the standard missile, however they are expensive to manufacture and are in limited supply. Modify your program such that if the missile is between 0 and 10 miles away, you will use the super-fast missile, but if it is between 10 and 30 miles away, you'll use the standard missile.

  2. New Simulations have shown that if the missile is less than 3 miles out, there is no chance of intercepting it, even with the ultra missile. Modify your program so that if the missile is 0 - 3 miles away, an evacuation order is given.