Using the Class diagram, modify the Airplane class to: Using the Class diagram,
ID: 3627805 • Letter: U
Question
Using the Class diagram, modify the Airplane class to:
Using the Class diagram, modify the Jet Fighter to:
Using the Class diagram, modify the Passenger Airplane class to:
Ensure that the Windows Form correctly implements each of the operations using the modified class architecture:
* The name of the Airplane class has been renamed to Airplane_Abstract and the bold, italic letters specify that the entire class should be defined as an abstract class. * The members in normal case font indicate that these members are declared as class-level members and the implementation of these members is done in the parent class. * Methods in italic letters are pure virtual functions that have no implementation in the base class, and MUST be overridden in the derived classes. * The Move method is a virtual method in the base class, but can be overridden in the derived classes. This will work in the Fighter Jet class in this example, BUT not in the Passenger Airplane class. Using the Class diagram, modify the Airplane class to: Specify that the class is abstract Specify that the Move method is a virtual method Specify that TurnRight, TurnLeft, Accelerate, and Decelerate are pure virtual methods. Remove the code from each of the methods (copy and paste it into a Notepad file, since you will want to use it in each of the derived class's implementation of the methods). Using the Class diagram, modify the Jet Fighter to: Using the same algorithms and formulas from Week 5 (and Week 3) for the Fighter Jet class, implement each of the pure virtual functions: (1) TurnRight, (2) TurnLeft, (3) Accelerate, and (4) Decelerate. Override the base class Move method so that the Jet Fighter moves 10 times faster than a generic airplane. Using the Class diagram, modify the Passenger Airplane class to: Using the same algorithms and formulas from Week 5 (and Week 3) for the Fighter Jet class, implement each of the pure virtual functions: (1) TurnRight, (2) TurnLeft, (3) Accelerate, and (4) Decelerate. Ensure that the Windows Form correctly implements each of the operations using the modified class architecture: List box, or combo box control, that allows the user to select whether the airplane is a generic airplane, a passenger plane, or a fighter plane. When the user selects the type of plane, create a new object of the identified type. Add a command button that when selected provides the information about the specific type of airplane object. [Hint: program each event handler to handle a generic airplane object, then use the polymorphic methods]. When the user selects the existing operations, the appropriate object type methods will be invoked.
Explanation / Answer
public class Position { //Declaring Variables public int x; public int y; public double speed; public int direction; public Position() { } public Position(int x, int y, double speed, int direction) { this.x = x; this.y = y; this.speed = speed; this.direction = direction; } public int X { get { return x; } set { x = value; } } public int Y { get { return y; } set { y = value; } } public int Direction { get { return direction; } set { direction = value; } } public double Speed { get { return speed; } set { speed = value; } } // overridden ToString() method public override string ToString() { return " Position: X: " + X + " Y: " + Y + " Speed: " + Speed + " Direction: " + Direction; } } } class PassengerPlane : Airplane { //Declaring Variables private string airlineName; private int numberPassengers; private int flightNumber; //Creating Module PassengerPlane public PassengerPlane(int x, int y, double speed, int direction, string airlineName1, int numberPassengers1, int flightNumber1, string strname) : base(x, y, speed, direction, strname) { airlineName = airlineName1; numberPassengers = numberPassengers1; flightNumber = flightNumber1; } //Creating Module Board Plane public static void BoardPlane() { //Creating Message box to show text System.Windows.Forms.MessageBox.Show("The plane has now been boarded"); } //over riding the data from parent module ToString public override string ToString() { return "Name: " + Name + PlanePosition.ToString() + System.Environment.NewLine + "Airline Name: " + airlineName.ToString() + System.Environment.NewLine + "Number of Passengers: " + numberPassengers.ToString() + System.Environment.NewLine + "Flight Number: " + flightNumber.ToString(); } //over riding the data from parent module Turn Right public override void TurnRight() { base.TurnRight(); } //over riding the data from parent module Turn Left public override void TurnLeft() { base.TurnLeft(); } //over riding the data from parent module Accelerate public override void Accelerate() { base.Accelerate(); } //over riding the data from parent module Decelerate public override void Decelerate() { if (PlanePosition.Speed > 0) if (PlanePosition.Speed - 10 < 0) PlanePosition.Speed = 0; else PlanePosition.Speed -= 10; } } } class FighterJet : Airplane { private string fighterType; public FighterJet(int x, int y, double speed, int direction, string strfighterType, string strname) :base(x, y, speed, direction, strname) { fighterType = strfighterType; } //over riding the data from parent module ToString public override string ToString() { return "Airplane Name: " + Name + System.Environment.NewLine + "Fighter Type: " + fighterType.ToString() + PlanePosition.ToString(); } //over riding the data from parent module Turn Right public override void TurnRight() { if (PlanePosition.Direction < 359) PlanePosition.Direction -= 20; else PlanePosition.Direction = 0; } //over riding the data from parent module Turn Left public override void TurnLeft() { if (PlanePosition.Direction < 359) PlanePosition.Direction += 20; else PlanePosition.Direction = 0; } //over riding the data from parent module Accelerate public override void Accelerate() { if (PlanePosition.Speed 0) if (PlanePosition.Speed - 100 < 0) PlanePosition.Speed = 0; else PlanePosition.Speed -= 100; } } } public class Airplane { //Declaring Variables public string name; private Position planePosition; private int numberCreated; private int MAX_SPEED = 500; public Airplane(int x, int y, double speed, int direction, string strname) { name = strname; planePosition = new Position(x, y, speed, direction); numberCreated = numberCreated + 1; } public string Name { get { return name; } set { name = value; } } public Position PlanePosition { get { return planePosition; } set { planePosition = value; } } // overridden ToString() method public override string ToString() { return "Name: " + Name + System.Environment.NewLine + PlanePosition.ToString(); } // Procedure moves the positioning of the airplane by updating the value of X and Y public virtual void Move() { // convert degrees to radians since C# uses radians for Sine and Cosine functions double radians = planePosition.Direction * Math.PI / 180.0; // change the x location by the x vector of the speed planePosition.X += (int)(planePosition.Speed * Math.Cos(radians)); // change the y location by the y vector of the speed planePosition.Y -= (int)(planePosition.Speed * Math.Sin(radians)); } // procedure will cause the plane to "turn right" public virtual void TurnRight() { if (planePosition.Direction > 0) // or direction -= 1; planePosition.Direction -= 1; else // reset direction to fit within 0 - 359 degrees planePosition.Direction = 359; } // Procedure will cause the plane to "turn left" public virtual void TurnLeft() { if (planePosition.Direction < 359) // or direction += 1; planePosition.Direction += 1; else // reset direction to fit within 0 - 359 degrees planePosition.Direction = 0; } // Procedure will update the speed of the plane public virtual void Accelerate() { if (planePosition.Speed 0) // or speed -= 1; planePosition.Speed -= 1; } // return the total number of airplanes created using the class as the blueprint public int GetNumberCreated() { // returns the number of airplanes created return numberCreated + 1; } } } public partial class FrmAirplane : Form { Airplane myAirplane; FighterJet myFighterJet; PassengerPlane myPassengerPlane; public FrmAirplane() { InitializeComponent(); } Airplane airplane; private void btnCreate_Click_1(object sender, EventArgs e) { //What will happen if Generic Airplane is chosen from Airplane Type combo box if (cboAirplaneType.Text == "Generic Airplane") { myAirplane = new Airplane(Convert.ToInt32(txtX.Text), Convert.ToInt32(txtY.Text), Convert.ToDouble(txtSpeed.Text), Convert.ToInt32(txtDirection.Text), txtName.Text); txtNumCreated.Text = myAirplane.GetNumberCreated().ToString(); lblMessage.Text = myAirplane.ToString(); } //What will happen if Passenger Airplane is chosen from Airplane Type Combo box else if (cboAirplaneType.Text == "Passenger Airplane") { myPassengerPlane = new PassengerPlane(Convert.ToInt32(txtX.Text), Convert.ToInt32(txtY.Text), Convert.ToDouble(txtSpeed.Text), Convert.ToInt32(txtDirection.Text), txtAirlineName.Text, Convert.ToInt32(txtNumberofPassengers.Text), Convert.ToInt32(txtFlightNumber.Text), txtName.Text); txtNumCreated.Text = myPassengerPlane.GetNumberCreated().ToString(); lblMessage.Text = myPassengerPlane.ToString(); } //What will happen if Passenger Airplane is chosen from Airplane Type Combo box else if (cboAirplaneType.Text == "Fighter Plane") { myFighterJet = new FighterJet(Convert.ToInt32(txtX.Text), Convert.ToInt32(txtY.Text), Convert.ToDouble(txtSpeed.Text), Convert.ToInt32(txtDirection.Text), txtFighterType.Text, txtName.Text); txtNumCreated.Text = myFighterJet.GetNumberCreated().ToString(); lblMessage.Text = myFighterJet.ToString(); } } private void btnMove_Click(object sender, EventArgs e) { // calling Airplane class method Move() using airplane object airplane.Move(); lblMessage.Text = airplane.ToString(); } private void btnTurnLeft_Click_1(object sender, EventArgs e) { // What will take place if Airplane Type Combo Box = Generic Airplane if (cboAirplaneType.Text == "Generic Airplane") { airplane.TurnLeft(); lblMessage.Text = airplane.ToString(); } // What will take place if Airplane Type Combo Box = Passenger Airplane else if (cboAirplaneType.Text == "Passenger Airplane") { myPassengerPlane.TurnLeft(); lblMessage.Text = myPassengerPlane.ToString(); } // What will take place if Airplane Type Combo Box = Fighter Plane else if (cboAirplaneType.Text == "Fighter Plane") { myFighterJet.TurnLeft(); lblMessage.Text = myFighterJet.ToString(); } } private void btnTurnRight_Click_1(object sender, EventArgs e) { // What will take place if Airplane Type Combo Box = Generic Airplane if (cboAirplaneType.Text == "Generic Airplane") { airplane.TurnRight(); lblMessage.Text = airplane.ToString(); } // What will take place if Airplane Type Combo Box = Passenger Airplane else if (cboAirplaneType.Text == "Passenger Airplane") { myPassengerPlane.TurnRight(); lblMessage.Text = myPassengerPlane.ToString(); } // What will take place if Airplane Type Combo Box = Fighter Plane else if (cboAirplaneType.Text == "Fighter Plane") { myFighterJet.TurnRight(); lblMessage.Text = myFighterJet.ToString(); } } private void btnClear_Click(object sender, EventArgs e) { //calling Clear fields method clearFields(); //Message box to display once fields have been cleared System.Windows.Forms.MessageBox.Show("All fields on the form have now been updated to a null value."); } private void btnExit_Click(object sender, EventArgs e) { MessageBox.Show("Thank you. Click OK to Terminate", "Exit Application", MessageBoxButtons.OK, MessageBoxIcon.Information); Application.Exit(); } private void FrmAirplane_Load(object sender, EventArgs e) { //Calling the Display Application Information from the utilities class Utilities.DisplayApplicationInformation(); //Adding the following time zones to the combo box time zone cboAirplaneType.Items.Add("Generic Airplane"); cboAirplaneType.Items.Add("Passenger Airplane"); cboAirplaneType.Items.Add("Fighter Plane"); } private void lblMessage_Click(object sender, EventArgs e) { } private void btnBoardAirplane_Click_1(object sender, EventArgs e) { //Calling the Board Plane Method from the PassengerPlane class PassengerPlane.BoardPlane(); } private void cboAirplaneType_SelectedIndexChanged(object sender, EventArgs e) { } public void clearFields() { txtName.Text = ""; txtX.Text = ""; txtY.Text = ""; txtSpeed.Text = ""; txtDirection.Text = ""; cboAirplaneType.Text = ""; txtAirlineName.Text = ""; txtNumberofPassengers.Text = ""; txtFlightNumber.Text = ""; } private void btnAccelerate_Click_1(object sender, EventArgs e) { { // What will take place if Airplane Type Combo Box = Fighter Plane if (cboAirplaneType.Text == "Fighter Plane") { myFighterJet.Accelerate(); lblMessage.Text = myFighterJet.ToString(); } // What will take place if Airplane Type Combo Box = Generic Airplane else if (cboAirplaneType.Text == "Generic Airplane") { airplane.Accelerate(); lblMessage.Text = airplane.ToString(); } // What will take place if Airplane Type Combo Box = Passenger Airplane else if (cboAirplaneType.Text == "Passenger Airplane") { myPassengerPlane.Accelerate(); lblMessage.Text = myPassengerPlane.ToString(); } } } private void btnDecelerate_Click_1(object sender, EventArgs e) { { // What will take place if Airplane Type Combo Box = Generic Airplane if (cboAirplaneType.Text == "Generic Airplane") { airplane.Decelerate(); lblMessage.Text = airplane.ToString(); } // What will take place if Airplane Type Combo Box = Passenger Airplane else if (cboAirplaneType.Text == "Passenger Airplane") { myPassengerPlane.Decelerate(); lblMessage.Text = myPassengerPlane.ToString(); } // What will take place if Airplane Type Combo Box = Fighter Plane else if (cboAirplaneType.Text == "Fighter Plane") { myFighterJet.Decelerate(); lblMessage.Text = myFighterJet.ToString(); } } } } }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.