Using the UML from above: Using the Class diagram, modify the Airplane class to:
ID: 3627661 • Letter: U
Question
Using the UML from above:
Using the Class diagram, modify the Airplane class to:
Using the Class diagram, create the PassengerAirplane class using the following specifications:
Using the Class diagram, create the JetFighter class using the following specifications:
Extend the Airplane information form to include the following controls:
Using the UML from above: Using the Class diagram, modify the Airplane class to: Create the ToString() method that overrides the System.Object ToString method that creates and returns a well-formatted string that contains the airplane name and position information. Modify the Accelerate and Decelerate methods so that they can be overridden by derived classes. Using the Class diagram, create the PassengerAirplane class using the following specifications: Board plane is a simple method that provides a message to the user that the plane has been boarded. Override the Airplane Accelerate method by invoking the base class accelerate method, and allow the plane to go 500 knots. Override the Airplane Decelerate method to allow the plane to decelerate in increments of 10. Override the ToString method by invoking the Airplane ToString method, and then adding the airline name, flight number, and number of passengers. Using the Class diagram, create the JetFighter class using the following specifications: Override the Airplane Accelerate method and allow the plane to go 2,000 knots, and accelerate in increments of 100. Override the Airplane Decelerate method to allow the plane to decelerate in increments of 100. Override the Airplane TurnLeft and TurnRight methods so that they turn in increments of 20 Override the ToString method by invoking the Airplane ToString method, and then adding the airline fighter type. Extend the Airplane information form to include the following controls: Add a 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
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace PlaneTypes.cs { public class Airplane { string name; Position planePosition; int numberCreated; const int MAX_SPEED = 500; public Airplane() { } public Airplane(string name, Position p) { this.name = name; planePosition = new Position(p.X, p.Y, p.Speed, p.Direction); numberCreated = numberCreated + 1; } public string Name { get { return name; } set { name = value; } } public Position PlanePosition { get { return planePosition; } set { planePosition = value; } } public int GetNumberCreated() { return numberCreated + 1; } public override string ToString() { return "Name: " + Name + PlanePosition.ToString(); } public void Move() { double radians = planePosition.Direction * Math.PI / 180.0; planePosition.X += (int)(planePosition.Speed * Math.Cos(radians)); planePosition.Y -= (int)(planePosition.Speed * Math.Sin(radians)); } public virtual void TurnRight() { if (planePosition.Direction > 0) planePosition.Direction -= 1; else planePosition.Direction = 359; } public virtual void TurnLeft() { if (planePosition.Direction < 359) planePosition.Direction += 1; else planePosition.Direction = 0; } public virtual void Accelerate() { if (planePosition.Speed 0) planePosition.Speed -= 1; } } public class Position { int x, y, direction; double speed; 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; } } public override string ToString() { return " Position: X: " + X + " Y: " + Y + " Speed: " + Speed + " Direction: " + Direction; } } class PassengerPlane : Airplane { string airlineName; int numberPassengers, flightNumber; public PassengerPlane(string name, Position pos, int flight, int numPass) { this.airlineName = name; this.flightNumber = flight; this.numberPassengers = numPass; this.Name = name; this.PlanePosition = new Position(pos.X, pos.Y, pos.Speed, pos.Direction); } public void BoardPlane() { Console.WriteLine("Plane has been boarded"); } public override string ToString() { return base.ToString() + " : " + airlineName + " : " + flightNumber.ToString() + " : " + numberPassengers.ToString(); } public override void TurnRight() { base.TurnRight(); } public override void TurnLeft() { base.TurnLeft(); } public override void Accelerate() { base.Accelerate(); } public override void Decelerate() { if (PlanePosition.Speed > 0) if (PlanePosition.Speed - 10 < 0) PlanePosition.Speed = 0; else PlanePosition.Speed -= 10; } } class FighterJet : Airplane { string fighterType; public FighterJet(string name, Position pos, string type) { this.fighterType = type; this.Name = name; this.PlanePosition = new Position(pos.X, pos.Y, pos.Speed, pos.Direction); } public override string ToString() { return base.ToString() + " : " + fighterType; } public override void TurnRight() { if (PlanePosition.Direction < 359) PlanePosition.Direction -= 20; else PlanePosition.Direction = 0; } public override void TurnLeft() { if (PlanePosition.Direction < 359) PlanePosition.Direction += 20; else PlanePosition.Direction = 0; } public override void Accelerate() { if (PlanePosition.Speed < 2000) if (PlanePosition.Speed + 100 < 2000) PlanePosition.Speed += 100; } public override void Decelerate() { if (PlanePosition.Speed > 0) if (PlanePosition.Speed - 100 < 0) PlanePosition.Speed = 0; else PlanePosition.Speed -= 100; } } }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.