Create new C# windows form application project (Vehicles_Tester) Add a new class
ID: 3890432 • Letter: C
Question
Create new C# windows form application project (Vehicles_Tester)
Add a new 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)
Add a class: Person (_firstname, _lastname, List<Vehicle> 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
// The Vehicle library code, GUI is not included as the question has many parts
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VehiclesLib
{
public class Vehicle
{
//
// initialise the private data members for the class
string _make;
//
string _model;
//
int _year;
//
double _price;
//
string _vin;
//
// define a default constructor for initialisation
public Vehicle()
{
Console.WriteLine("Empty vehicle object initialised");
}
//
// define a parameterized constructor
public Vehicle(string make, string model, int year, double price, string vin)
{
//
_make = make;
//
_model = model;
//
_year = year;
//
_price = price;
//
_vin = vin;
}
//
// define a properties for getting the vehicle info
public string Make
{
// only the getter is defined
get
{
//
return _make;
}
}
//
public string Model
{
//
get
{
//
return _model;
}
}
//
public string Vin
{
//
get
{
//
return _vin;
}
}
//
public int Year
{
//
get
{
//
return _year;
}
}
//
public double Price
{
//
get
{
//
return _price;
}
}
// add method UpdatePrice()
public void UpdatePrice(double newPrice)
{
//
_price = newPrice;
//
Console.WriteLine("Price Updated");
}
//
}
//
// define the class Person
public class Person
{
//
string _firstname;
//
string _lastname;
//
List<Vehicle> vehicleList = new List<Vehicle>();
//
// add constructor
public Person()
{
//
Console.WriteLine("Empty Person object created");
}
//
public Person(string firstname, string lastname, List<Vehicle>vehicle_List)
{
//
_firstname = firstname;
///
_lastname = lastname;
//
vehicleList.AddRange(vehicle_List); // add the entire vehicle list to the collection
}
//
// add properties
public string FirstName
{
//
get
{
//
return _firstname;
}
}
//
public string LastName
{
//
get
{
//
return _lastname;
}
}
//
public List<Vehicle> VehicleList
{
//
get
{
//
return vehicleList;
}
}
//
// define the method Add()
public void Add(Vehicle v)
{
//
vehicleList.Add(v);
}
//
// define method remove
public void Remove(string vin)
{
//
//Vehicle v;
foreach (Vehicle v in vehicleList)
{
//
if (v.Vin == vin)
{
//
vehicleList.Remove(v);
}
}
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.