Curious
2011-05-19 08:51:33 UTC
Analyze the following class diagram for the Airplane and Position classes: a UML diagram for the Airplane class. Note the following key points:
The airplane "planePosition" attribute is an object of type Position.
The airplane GetNumberCreated is a static method.
The position MAX_Speed is a constant
http://devryu.net/ec/courses/63221/CRS-CIS247A-5077244/Graphics/iLabs%20Images/iLab%203.jpg
STEP 2: Code the Classes
Using the UML Diagrams from Step 1, code the Airplane and Position classes in the new project using the following specifications:
Add the following line to each of the constructors (in addition to setting default or given values):
numberCreated++; // increment the numberCreated each time an Airplane object is created
Add the following code to the Move( ) method:
// convert degrees to radians since C# uses radians for Sine and Cosine functions
double radians = direction * Math.PI / 180.0;
// change the x location by the x vector of the speed
x += (int)(speed * Math.Cos(radians)); // notice typecasting to int
// change the y location by the y vector of the speed
y -= (int)(speed * Math.Sin(radians)); // notice the -= operator (minus equals)
Add the following code to the TurnRight( ) method:
// turn right relative to the airplane
if( direction > 0 ) direction = direction – 1; // or direction -= 1;
else direction = 359; // reset direction to fit within 0 - 359 degrees
Add the following code to the TurnLeft( ) method:
// turn left relative to the airplane
if( direction < 359 ) direction = direction + 1; // or direction += 1;
else direction = 0; // reset direction to fit within 0 - 359 degrees
Add the following code to the Accelerate( ) method:
// increase the speed of the airplane
if( speed < MAXSPEED ) speed = speed + 1; // or speed += 1;
Add the following code to the Decelerate( ) method:
// decrease the speed of the airplane
if( speed > 0 ) speed = speed - 1; // or speed -= 1;
Add the following code to the GetNumberOfAirplanesCreated ( ) static method:
// return the total number of airplanes created using the class as the blueprint
return numberCreated; // returns the number of airplanes created
Be sure you follow proper commenting and programming styles (indentation, line spacing, etc).
STEP 3: Create the Windows Interface Form
Add a new form called “frmAirplane” to the project.
Provide textbox input fields for each of the attributes in the Airplane and Position classes. Ensure that each input is appropriately validated and the program shall only store valid inputs.
Ensure that each textbox has a label describing the purpose of the input field (called a label, field pair).
Add command buttons that correspond to each of the operations in the Airplane class, and include event handlers that invoke the associated method.
The event handler for each operation should display the position information before the action is taken, then display the information after the action is taken.
Add a command button that allows the user to add an additional airplane, and for each airplane added, add a label on the form that displays how many airplane objects are created.
Add a command button that will clear all input fields.
Add a command button that will exit the application.