Создать абстрактный класс Vehicle (транспортное средство) - C# (203883)
Формулировка задачи:
Доброго времени суток,дорогие!
Суть моего вопроса такова:имеется задание
1- Создать абстрактный класс Vehicle (транспортное средство). На его основе реализовать
классы Plane (самолет), Саг (автомобиль) и Ship (корабль). Классы
должны иметь возможность задавать и получать координаты и параметры
средств передвижения (цена, скорость, год выпуска и т. п.) с помощью свойств.
Для самолета должна быть определена высота, для самолета и корабля — количество
пассажиров, для корабля — порт приписки. Динамические характеристики
задать с помощью методов.
Которое в общем-то довольно легко реализовать:
но вот смущает меня то,что смысла в абстактности-0 и последняя строчка условия.Может быть кто-то что-то подскажет.Заранее спасибо
public abstract class Vehicle
{
private string name;
private double price;
private int madeYear;
private double speed;
private string mark;
public Vehicle(string name, double price, int madeYear, double speed, string mark)
{
this.name = name;
this.price = price;
this.madeYear = madeYear;
this.speed = speed;
this.mark = mark;
}
public Vehicle()
{
this.name = null;
this.price = 0;
this.madeYear = DateTime.Today.Year;
this.speed = 0;
this.mark = null;
}
#region Properties
public string Name
{
get; set;
}
public double Speed
{
get;
set;
}
public string Mark
{ get; set; }
public int MadeYear
{ get; set; }
public double Price
{ get; set; }
#endregion
}
public class Car : Vehicle
{
private int capacity;
public Car() { }
public Car(string name, double price, int madeYear, double speed, string mark,int capacity)
: base(name, price, madeYear, speed, mark) { this.capacity=capacity;}
public int Сapacity
{
get
{
return this.capacity;
}
set
{
if (value < 0)
throw new Exception("Capacity parameter must be greater than zero");
else
this.capacity = value;
}
}
}
public class Plane : Vehicle
{
private double high;
private int capacity;
public Plane() { this.high = 0;
this.capacity = 0;
}
public Plane(string name, double price, int madeYear, double speed, string mark, double high,int capacity)
: base(name, price, madeYear, speed, mark)
{
this.high = high;
if (capacity < 0)
throw new Exception("Capacity parameter must be greater than zero");
else
this.capacity = capacity;
}
public double High
{
get;
set;
}
public int Сapacity
{
get
{
return this.capacity;
}
set
{
if (value < 0)
throw new Exception("Capacity parameter must be greater than zero");
else
this.capacity = value;
}
}
}
public class Ship : Vehicle
{
private string port;
private int capacity;
public Ship() {
this.capacity = 0;
this.port = null;
}
public Ship(string name, double price, int madeYear, double speed, string mark, int capacity,string port)
: base(name, price, madeYear, speed, mark)
{
this.port = port;
if (capacity < 0)
throw new Exception("Capacity parameter must be greater than zero");
else
this.capacity = capacity;
}
public int Сapacity
{
get
{
return this.capacity;
}
set
{
if (value < 0)
throw new Exception("Capacity parameter must be greater than zero");
else
this.capacity = value;
}
}
}
class Program
{
static void Main(string[] args)
{
Car car=new Car();
Plane j = new Plane();
j.Name="jj";
Console.WriteLine(j.Name);
}
}
Ну вот хоть убейте не понимаю,что значит :" Динамические характеристики
задать с помощью методов."...
Решение задачи: «Создать абстрактный класс Vehicle (транспортное средство)»
textual
Листинг программы
public class Plane : Vehicle
{
private double high;
...
public void setHigh(double curHigh)
{
high = curHigh;
}
}