Using C# window Form Add a class library project (VehiclesLib) To the Library pr
ID: 3889965 • Letter: U
Question
Using C# window Form Add a class library project (VehiclesLib) To the Library project
Add class: Vehicle (_make, _model, _year, _price, _vin), Add constructor and get properties, Method: UpdatePrice(decimal newPrice).
Then Add a class: Person (_firstname, _lastname, List vehicleList), Add constructor, get properties, Method: Add(Vehicle v), Method: Remove(string vin) (remove by vin number)
In Form1: create a list of person, preload the list with at least 7 people to each add at least 2 vehicles, provide gui to display all the people and their vehicles, provide gui to add a vehicle to a person, provide gui to update the price of a vehicle of a person, provide gui to remove (sell) a car of a person.
Explanation / Answer
Question contains many sub-question (in-fact it contains a complete project itself). So providing only first 4 answers as per guidelines of chegg.
1) Add class: Vehicle (_make, _model, _year, _price, _vin)
2) Add constructor and get properties
3) Method: UpdatePrice(decimal newPrice).
4) Add a class: Person (_firstname, _lastname, List vehicleList)
5) Add constructor, get properties
6) Method: Add(Vehicle v), Method: Remove(string vin) (remove by vin number)
namespace DataContracts
{
/// <summary>
/// Vehicle Class
/// </summary>
public class Vehicle
{
private static int idcount = 0;
#region private properties
private string _make;
private string _mode;
private int _year;
private decimal _price;
private string _vid;
private int _id;
#endregion
#region Properties
public string Make { get { return _make; } }
public string Mode { get { return _mode; } }
public int Year { get { return _year; } }
public decimal Price { get { return _price; } }
public string Vid { get { return _vid; } }
#endregion
#region constructor
public Vehicle(string make = "", string mode = "", int year = 1980, decimal price = 0, string vid = "")
{
_id = ++idcount;
_make = make;
_mode = mode;
_year = year;
_price = price;
_vid = vid;
}
#endregion
#region public methods
/// <summary>
/// To update the price of the vehicle.
/// </summary>
/// <param name="newPrice">new value.</param>
/// <returns>true if update is successfull.</returns>
public bool UpdatePrice(decimal newPrice)
{
// we can remove this validation also.
if (newPrice == 0)
return false;
_price = newPrice;
return true;
}
#endregion
}
}
namespace DataContracts
{
using System.Collections.Generic;
using System.Linq;
public class Person
{
private static int personCount = 0;
#region private properties
private string _firstname;
private string _lastname;
private IList<Vehicle> _vehicleList;
private int _pid;
#endregion
#region properties
public string Firstname { get { return _firstname; } }
public string Lastname { get { return _lastname; } }
public IList<Vehicle> VehicleList { get { return _vehicleList; } }
#endregion
#region constructor
public Person(string firstname = "", string lastname = "", IList<Vehicle> vehicleList = null)
{
_firstname = firstname;
_lastname = lastname;
_vehicleList = vehicleList;
}
#endregion
#region public methods
/// <summary>
/// to add vehicle.
/// </summary>
/// <param name="v">vehicle.</param>
/// <returns>true if succesfull.</returns>
public bool Add(Vehicle v)
{
if (v == null)
return false;
_vehicleList.Add(v);
return true;
}
/// <summary>
/// remove vehicle.
/// </summary>
/// <param name="vin">vehicle number.</param>
/// <returns>true if removed.</returns>
public bool Remove(string vin)
{
if (string.IsNullOrEmpty(vin))
return false;
((List<Vehicle>)_vehicleList).RemoveAll(v => v.Vid == vin);
return true;
}
#endregion
}
}
to create object, we can use
var v = new Vehicle("make","model",2005,50000, "TINA-1122");
we can also update the price:
v.updateprice(60000);
To display form,
we should create a grid. this grid should be bound with list of person and a subgrid should be bound with each person's vehicle list.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.