Question

In: Computer Science

What we want the program to do: We need to write a program, in Java, that...

What we want the program to do: We need to write a program, in Java, that will let the pilot issue commands to the aircraft to get it down safely on the flight deck. The program starts by prompting (asking) the user to enter the (start) approach speed in knots. A knot is a nautical mile and is the unit used in the navy and by the navy pilots. After the user enters the approach speed, the user is then shown the menu and the pilot picks a command. The effect of this command is then calculated and the updated information about the aircraft is displayed. If the aircraft has crashed or has landed, then the information is different. If the aircraft does not land, overshoot or crash, then the program presents the menu again and the user makes another choice (or the same choice again) and the program calculates the updated position of the aircraft and displays the information to the pilot (the user)' This continues until the aircraft successfully lands on the flight desk, the aircraft crashes or the aircraft overshoots the landing area. To successfully land, the aircraft must have its hook down and its gear down when it is in the valid landing zone. To be in the correct landing zone with the hook up and gear down, means the aircraft doesn't stop in time and has to go around, this is known as an overshoot. To be in the correct landing zone with the gear (landing gear) up means that the aircraft crashes. (Whether the hook is up or down doesn't matter) At any time, the user can issue the command Eject. This displays a message and stops the program, the aircraft crashes into the ocean. The commands and the changes they make are listed below. Note that commands must be case insensitive. That is, HOOK Down and hook dOWN must have the same effect. If the aircraft is still on approach, that is, it hasn't landed, overshot or crashed, the new height is shown along with the distance (which is to the back (stern) of the flight deck) and the glide path angle. The starting state of the aircraft is gear up, hook up and flaps level (= 0). An invalid command should not change anything about the conditions of the plane.

Sample starting run;

/*

Run 1: > java Ball

Enter speed (in knots) >> 120 //System in

Starting distance from carrier = 1000.00 feet

Starting height from carrier deck = 65.00 feet

Starting angle = 3.73 degrees

Flight Menu

Gear up

Gear down

Hook up

Hook down

Flaps up

Flaps down

Maintain

Power up

Power down

Eject

*/

To land an aircraft, the aircraft needs to begin its approach 65 feet above the height of the carrier deck and 1000 feet from the stern of the ship. The speed can vary and is set by the pilot. Once the aircraft speed is set, it remains the same until the aircraft lands. This is known as trimming the aircraft. Anything that decreases the power of the plane, makes it lose height, anything that increases the power of the plane, increases the height, the speed stays the same. To land successfully on the flight deck of a carrier, the aircraft must touch down in the first 400 feet after it crosses over the stern. If the aircraft does not land in this distance, the aircraft has to accelerate down the flight deck and try again. This is known as a "go round" or a "bolter". To help the aircraft land on the deck, the plane deploys (lowers) a 15 foot long hook. This the arrestor hook and is designed to catch one of the three arrestors wires, strung across the deck. What this means is that the aircraft does not have to get down to 0 feet above the flight deck, so long as it is within 15 feet above the flight deck, then the hook will catch a wire and drag the plane down onto the deck. This is perfectly acceptable and counts as a good landing. (Carrier landings are often described as a controlled crash) A successful landing follows a glide path of 3 degrees. See the diagram on page 5. This will be modelled in the program as any angle between 1 and 5 degrees. There is an aid on the port (left) side of the flight deck, which consists of a Fresnel lens, otherwise known as the "Ball" As the pilot approaches the flight deck, the "Ball" shows different coloured lights If the angle is between 1 and 5 degrees (both inclusive), then the light is green, that means continue on the current glide, on track for a good landing. Amber, angle is between 5 (exclusive) and 10 (inclusive) means too high, the aircraft is going to overshoot the arrestor wires (recall that this is the first 400 feet of the flight deck starting at the stern (rear) of the ship). The pilot needs to do something to reduce the power of the aircraft to get it back to the correct flight path. If the distance is greater than 0, and the angle is between 10 (exclusive) and 15 (inclusive), the light is red (not blinking).

If the angle is less than 1 and the distance is greater than or equal to 0, then the light flashes blinking red (about to crash into the ship or the ocean) If the distance is greater than 0 and the angle is greater than 15, the light is blinking red, the aircraft is way too high. Only display the angle if the distance is greater than or equal to 0, once over the flight deck, do not show the angle or the colour of the light. Each time the pilot makes a change to the aircraft (and remember that at the very least it is always travelling forward towards the carrier) the pilot checks the updated status of the "Ball", and makes corrections if required.

How to work out the angle. One way is take the arctan of the angle formed by height and the distance. tan θ = a / b = height / distance what we want is the actual angle, so once we know tan θ, we need to take tan-1 to give us the figure for the angle in degrees. All of this uses methods that are in the java Math class that we have been using since the start of the semester. The Math class java method for finding the actual angle in degrees, from a tan figure, that is, doing tan-1 is atan(number) NOTE: all interactions with the Math class methods have to be in radians, not angles, even though we want the final result to be an angle in degrees. All calculations in this program need to be in feet, see the diagram above. The conversion factor, between knots per hour and feet per second is 1.688. Each time a valid command is issued the distance to the carrier deck is calculated. Each loop through the menu (valid commands only) represents 1 sec of time. So, for example, if the speed was set at 100 knots, then the aircraft would travel 100 * 1.688 feet in one second. Carrier sea level (0 feet) rear of the flight deck 65 ' above the carrier deck (height) 1000 ' horizontal distance glide path angle, should be 3 degrees aircraft starts here ' = feet

The new distance to the carrier would be distance = distance - (knots * 1.688) (new distance = old distance - ( knots * 1.688)

If this was after the first second, then at 100 knots, the new distance would be distance = 1000 - (100 * 1.688) = 1000 - 168.8 = 831.2 feet

The commands and their effects are listed below. Recall that the aircraft is always moving forward at the speed set at the start of the program. The allowed commands and the change they make: Gear Up This increases the height + 20 feet (this is a one off effect) If the gear is already up, then an appropriate message is displayed to the screen and the height is not changed. Gear Down This decreases the height 20 feet (this is a one off effect) If the gear is already down, then an appropriate message is displayed to the screen and the height is not changed. Hook up This increases the height + 10 feet (this is a one off effect) If the hook is already up, then an appropriate message is displayed to the screen and the height is not changed. Hook Down This decreases the height 10 feet (this is a one off effect) If the hook is already down, then an appropriate message is displayed to the screen and the height is not changed. Flaps Up This increases the height + 15 feet (this is a one off effect) If the flaps are already fully up, then an appropriate message is displayed to the screen. The height is changed by +15, even if the flaps are already fully up. Flaps Down This decreases the height 15 feet (this is a one off effect) If the flaps are already fully down, then an appropriate message is displayed to the screen. The height is changed by - 15, even if the flaps are already fully down. To go from flaps fully up to flaps fully down requires 2 steps, the first time the Flaps down command is issued the flaps go to level, then the next time the flaps down command is issued, they go to fully down. If the flaps are level, they do not change the height on the next time through the menu. This is the same for flaps up, if the flaps are fully down, then the command flaps up brings the flaps to level, the next flaps up command would see the flaps go from level to fully up. Maintain This command does not change the height, just flies straight and level. Note that the one thing this command must do is set the flaps to the level position. The distance changes. Power Up This command increases the height by 5 Only certain commands are allowed, these are entered as text (not numbers) Invalid commands should be ignored

Power Down This command decreases the height by 5 Eject ends the program, after a screen message The distance, angle and height figures must be displayed to 2 decimal places. Your program must correctly deal with the user entering an invalid command (not one of the commands listed above). If the user enters an invalid command, an appropriate message is displayed to the screen, and nothing is changed, just go straight back to the menu again. The program ends when the aircraft lands, crashes or overshoots, or the user selects the Eject command. Sample runs of the program are included below (user input is in bold): (Note: not all options, functionality and messages are shown.)

1) Run 1: > java Ball

Enter speed (in knots) >> 120

Starting distance from carrier = 1000.00 feet

Starting height from carrier deck = 65.00 feet

Starting angle = 3.73 degrees

Flight Menu

Gear up

Gear down

Hook up

Hook down

Flaps up

Flaps down

Maintain

Power up

Power down

Eject

2) Enter command >> power down

Distance from carrier = 797.44 feet

Height from carrier deck = 60.00 feet

Angle = 4.32 degrees

Light showing

GREEN

On the glide path

Flight Menu

Gear up

Gear down

Hook up

Hook down

Flaps up

Flaps down

Maintain

Power up

Power down

Eject

3) Enter command >> hook down

Distance from carrier = 594.88 feet

Height from carrier deck = 50.00 feet

Angle = 4.83 degrees Light showing

GREEN

On the glide path

Flight Menu

Gear up

Gear down

Hook up

Hook down

Flaps up

Flaps down

Maintain

Power up

Power down

Eject

4) Enter command >> power down

Distance from carrier = 392.32 feet

Height from carrier deck = 45.00 feet

Angle = 6.60 degrees Light showing

AMBER

TOO HIGH!!! Reduce power

Flight Menu

Gear up

Gear down

Hook up

Hook down

Flaps up

Flaps down

Maintain

Power up

Power down

Eject

5) Enter command >> hook down

Hook is already down!

Flight Menu

Gear up

Gear down

Hook up

Hook down

Flaps up

Flaps down

Maintain

Power up

Power down

Eject

6) Enter command >> gear down

Distance from carrier = 189.76 feet

Height from carrier deck = 25.00 feet

Angle = 7.59 degrees

Light showing

AMBER TOO HIGH!!!

Reduce power

Flight Menu

Gear up

Gear down

Hook up

Hook down

Flaps up

Flaps down

Maintain

Power up

Power down

Eject

7) Enter command >> flaps down

Distance from carrier = -12.80 feet

Height from carrier deck = 10.00 feet

Congratulations!!

Landing on a carrier deck is the hardest thing

well done

Solutions

Expert Solution

import java.lang.*;
import java.util.*;
public class Ex
{
   public static void getA(double x,double y)
   {
       if(x>=1 && x<=5)
       {
           System.out.println("Light Showing");
           System.out.println("GREEN");
           System.out.println("On the glide path");
       }
       else if(x>5 && x<=10)
       {
           System.out.println("Light showing");
           System.out.println("AMBER");
           System.out.println("TOO HIGH!!! Reduce power");
       }
       else if(x>10 && x<=15)
       {
           System.out.println("Light showing");
           System.out.println("RED");
           System.out.println("Not blinking");
       }
       else if(x<1 && y>=0)
       {
           System.out.println("Light showing");
           System.out.println("Blinking RED");
           System.out.println("about to crash into the ship or ocean");
       }
       else if(x>15 && y>0)
       {
           System.out.println("Light showing");
           System.out.println("Blinking RED");
           System.out.println("the aircraft way is too high");
       }
   }
   public static void main(String[] args)
   {
       Scanner sc=new Scanner(System.in);
       double sd=1000.0;
       double sh=65.00;
       double ang=3.73;
       System.out.println("Enter speed (in knots)");
       int speed=sc.nextInt();
       System.out.println("Starting distance from carrier="+sd+" feet");
       System.out.println("Starting height from carrier deck="+sh+" feet");
       System.out.println("Starting angle="+ang+" degrees");
       System.out.println("Flight Menu");
       System.out.print("Gear up\nGear down\nHook up\nHook down\nFlaps up\nFlaps down\nMaintain\nPower up\nPower down\nEject\n");
       String a[]=new String[10];
       a[0]=Gear up;
       a[1]=Gear down;
       a[2]=Hook up;
       a[3]=Hook down;
       a[4]=Flaps up;
       a[5]=Flaps down;
       a[6]=Maintain;
       a[7]=Power up;
       a[8]=Power down;
       a[9]=Eject;
       int gu=0,gd=0,hu=0,hd=0,fu=0,fd=0;
       do
       {
String ch;
System.out.println("Enter command");
String ip=sc.next();
for(int i=0;i<10;i++)
if(ip.equalsIgnoreCase(a[i]))
{
ch=a[i];
break;
}
       switch(ch)
       {
           case "Gear up":if(gu==1)
                       System.out.println("Gear is already up");
                   else
                   {
                   sd=sd-(speed*1.688);
                   sh=sh+20;
                   angle=java.lang.Math.atan(sh/sd);
                   System.out.println("Distance from carrier="+sd+" feet");
                   System.out.println("Height from carrier deck="+sh+" feet");
                   if(sd>=0)
                   {
                       System.out.println("Angle="+ang+" degrees");
                       getA(angle,sd);
                   }
                   gu=1;
                   }
                   break;
           case "Gear down":if(gd==1) System.out.println("Gear is already down");
                   else{
                   sd=sd-(speed*1.688);
                   sh=sh-20;
                   angle=java.lang.Math.atan(sh/sd);
                   System.out.println("Distance from carrier="+sd+" feet");
                   System.out.println("Height from carrier deck="+sh+" feet");
                   if(sd>=0)
                   {
                       System.out.println("Angle="+ang+" degrees");
                       getA(angle,sd);
                   }
                   gd=1;}
                   break;
           case "Hook up":if(hu==1) System.out.println("Hook is already up");
                   else
                   {sd=sd-(speed*1.688);
                   sh=sh+10;
                   angle=java.lang.Math.atan(sh/sd);
                   System.out.println("Distance from carrier="+sd+" feet");
                   System.out.println("Height from carrier deck="+sh+" feet");
                   if(sd>=0)
                   {
                       System.out.println("Angle="+ang+" degrees");
                       getA(angle,sd);
                   }
                   hu=1;}
                   break;
           case "Hook down":if(hd==1) System.out.println("Hook is already down");
                   else{sd=sd-(speed*1.688);
                   sh=sh-10;
                   angle=java.lang.Math.atan(sh/sd);
                   System.out.println("Distance from carrier="+sd+" feet");
                   System.out.println("Height from carrier deck="+sh+" feet");
                   if(sd>=0)
                   {
                       System.out.println("Angle="+ang+" degrees");
                       getA(angle,sd);
                   }
                   hd=1;}
                   break;
           case "Flaps up":sd=sd-(speed*1.688);
                   sh=sh+15;
                   angle=java.lang.Math.atan(sh/sd);
                   System.out.println("Distance from carrier="+sd+" feet");
                   System.out.println("Height from carrier deck="+sh+" feet");
                   if(sd>=0)
                   {
                       System.out.println("Angle="+ang+" degrees");
                       getA(angle,sd);
                   }
                   break;
           case "Flaps down":sd=sd-(speed*1.688);
                   sh=sh-15;
                   angle=java.lang.Math.atan(sh/sd);
                   System.out.println("Distance from carrier="+sd+" feet");
                   System.out.println("Height from carrier deck="+sh+" feet");
                   if(sd>=0)
                   {
                       System.out.println("Angle="+ang+" degrees");
                       getA(angle,sd);
                   }
                   break;
           case "Maintain":sd=sd-(speed*1.688);
                   angle=java.lang.Math.atan(sh/sd);
                   System.out.println("Distance from carrier="+sd+" feet");
                   System.out.println("Height from carrier deck="+sh+" feet");
                   if(sd>=0)
                   {
                       System.out.println("Angle="+ang+" degrees");
                       getA(angle,sd);
                   }
                   break;
           case "Power up":sd=sd-(speed*1.688);
                   sh=sh+5;
                   angle=java.lang.Math.atan(sh/sd);
                   System.out.println("Distance from carrier="+sd+" feet");
                   System.out.println("Height from carrier deck="+sh+" feet");
                   if(sd>=0)
                   {
                       System.out.println("Angle="+ang+" degrees");
                       getA(angle,sd);
                   }
                   break;
           case "Power down":sd=sd-(speed*1.688);
                   sh=sh-5;
                   angle=java.lang.Math.atan(sh/sd);
                   System.out.println("Distance from carrier="+sd+" feet");
                   System.out.println("Height from carrier deck="+sh+" feet");
                   if(sd>=0)
                   {
                       System.out.println("Angle="+ang+" degrees");
                       getA(angle,sd);
                   }
                   break;
           case "Eject":System.out.println("Distance from carrier="+sd+" feet");
                   System.out.println("Height from carrier deck="+sh+" feet");
                   System.out.println("Angle="+ang+" degrees");
                   System.out.print(Congratulations!!\nLanding on a carrier deck is the hardest thing\nwell done");
                   break;
           default:System.out.println("Invalid command");
       }
       if(ch=="Eject")
           break;
       if(sd<0 && ch!="Eject")
       {
           System.out.print(Congratulations!!\nLanding on a carrier deck is the hardest thing\nwell done");
           break;
       }  
       }
   }
}

//I have struck in evaluating flaps and i am pretty sure of remaining commands.


Related Solutions

Need in JAVA. You are to use Binary Trees to do this Program. Write a complete...
Need in JAVA. You are to use Binary Trees to do this Program. Write a complete program, which will process several sets of numbers: For each set of numbers you should: 1. Create a binary tree. 2. Print the tree using “inorder”, “preorder”, and “postorder”. 3. Call a method Count which counts the number of nodes in the tree. 4. Call a method Children which prints the number of children each node has. 5. Inset and delete several nodes according...
I want to write this program in java. Write a simple airline ticket reservation program in...
I want to write this program in java. Write a simple airline ticket reservation program in java.The program should display a menu with the following options: reserve a ticket, cancel a reservation, check whether a ticket is reserved for a particular person, and display the passengers. The information is maintained on an alphabetized linked list of names. In a simpler version of the program, assume that tickets are reserved for only one flight. In a fuller version, place no limit...
Write a complete program in java that will do the following:
Write a complete program in java that will do the following:Sports:             Baseball, Basketball, Football, Hockey, Volleyball, WaterpoloPlayers:           9, 5, 11, 6, 6, 7Store the data in appropriate arraysProvide an output of sports and player numbers. See below:Baseball          9 players.Basketball       5 players.Football           11 players.Hockey            6 players.Volleyball        6 players.Waterpolo       7 players.Use Scanner to provide the number of friends you have for a team sport.Provide an output of suggested sports for your group of friends. If your...
DO THIS IN JAVA Write a complete Java program. the program has two threads. One thread...
DO THIS IN JAVA Write a complete Java program. the program has two threads. One thread prints all capital letters 'A' to'Z'. The other thread prints all odd numbers from 1 to 21.
DO THIS PROGRAM IN JAVA Write a complete Java console based program following these steps: 1....
DO THIS PROGRAM IN JAVA Write a complete Java console based program following these steps: 1. Write an abstract Java class called Shape which has only one abstract method named getArea(); 2. Write a Java class called Rectangle which extends Shape and has two data membersnamed width and height.The Rectangle should have all get/set methods, the toString method, and implement the abstract method getArea()it gets from class Shape. 3. Write the driver code tat tests the classes and methods you...
URGENT!!! DO THIS PROGRAM IN JAVA Write a complete Java console based program following these steps:...
URGENT!!! DO THIS PROGRAM IN JAVA Write a complete Java console based program following these steps: 1. Write an abstract Java class called Shape which has only one abstract method named getArea(); 2. Write a Java class called Rectangle which extends Shape and has two data membersnamed width and height.The Rectangle should have all get/set methods, the toString method, and implement the abstract method getArea()it gets from class Shape. 3. Write the driver code tat tests the classes and methods...
IN JAVA PROGRAMMING Write a complete Java program to do the following: a) Prompt the user...
IN JAVA PROGRAMMING Write a complete Java program to do the following: a) Prompt the user to enter the name of the month he/she was born in (example: September). b) Prompt the user to enter his/her weight in pounds (example: 145.75). c) Prompt the user to enter his/her height in feet (example: 6.5). d) Display (print) a line of message on the screen that reads as follows: You were born in the month of September and weigh 145.75 lbs. and...
Write a program in Java to: Ask the user how many scores they want to enter...
Write a program in Java to: Ask the user how many scores they want to enter (=> Create an array based the entered size) Ask the user to enter their scores in the quarter (Fill the array with the entered scores(assigned to elements)) ==>> Use a "for" loop Find the greatest score Calculate and show the average Show the final grade based on the average (For example A,B,C ... ) Print the scores (the elements of the array) => Use...
Write a Java program that will first ask the user how many grades they want to...
Write a Java program that will first ask the user how many grades they want to enter. Then use a do…while loop to populate an array of that size with grades entered by the user. Then sort the array. In a for loop read through that array, display the grades and total the grades. After the loop, calculate the average of those grades and display that average. Specifications Prompt the user for the number of grades they would like to...
We have a list of runner and their running time, write a program in Java to...
We have a list of runner and their running time, write a program in Java to show the fastest runner and their time.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT