Plane Collision Program Object Oriented Programming Assignment: Project #1 BUIS 305-101

October 16, 2013

Group Members:

Carmara Royster Malik Petersen Charles Abegbesan Raven Anderson Carmara Royster, Malik Petersen, Charles Abegbesan, Ravan Anderson October 16, 2013 OOP - 305 Project #1

Write a program that receives distance and speed values for the plane and the closest moving object to the plane. The program must calculate the time to impact. If the time to impact, based on the parameters above, is less that 10s then the program will signal the plane to launch the passengers to safety.

Pseudo code:

Declare distance As double, planeSpeed As double, objectSpeed As double

Declare timeToCollision As double

INPUT distance

INPUT planeSpeed

INPUT objectSpeed

SET timeToCollision = distance / (planeSpeed + objectSpeed)

IF timeToCollision >= 10

OUTPUT “Safely averting the object” ELSE

OUTPUT “Ejecting passengers to safety” END IF Flow Chart:

Start

Distance As double, planeSpeed as double, objectSpeed as double

timeToCollision As double

timeToCollision = distance / {planeSpeed + objectSpeed}

if {timeToCollision >= 10

System.out.println("\nAvert object!"); System.out.println("\nEject passengers!");

End

Source Code:

/* package whatever; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */ class Ideone { public static void main (String[] args) throws java.lang.Exception { double distance, planeSpeed, objectSpeed; double timeToCollision;

Scanner input = new Scanner(System.in); System.out.print("Enter distance of nearest object: "); distance = input.nextDouble(); System.out.print("Enter speed of the plane: "); planeSpeed = input.nextDouble(); System.out.print("Enter speed of the object: "); objectSpeed = input.nextDouble(); //declarations above accounts for the two objects, the distance between, and the speed of both timeToCollision = distance / (planeSpeed + objectSpeed); //Input is plane speed + object speed / distance if (timeToCollision >= 10) { System.out.println("\nAvert object!"); //If the time remaining before a collision is less than 10 seconds, then the plane will not eject the passengers } else { System.out.println("\nEject passengers!"); //Else if the plane is equal to 10 seconds, it will eject the passengers }

} }