In: Computer Science
1. Make a Console App (.NET Core) in Visual Studio and name it as A1YourFirstnameLastname.
2. Implement a vehicle rental management system which is capable of doing the following: • View all, available and reserved vehicles. • Reserve vehicle or cancel a reservation.
3. The application must be menu-based app: 1 - View all vehicles 2 - View available vehicles 3 - View reserved vehicles 4 - Reserve a vehicle 5 - Cancel reservation 6 - Exit
4. NOTE: At no point should the application save any information to disk. All information is stored and managed in memory using a collection. The use of collections and the object-oriented design of the solution are an important part of the evaluation of your submission.
5. The rental company has inventory of cars and motorcycles.
• There are three categories of cars: Hatchback, Sedan, SUV
• And three categories of motorcycles: Cruiser, Sports, Dirt
• There are two types of cars: oStandard – a normal car oExotic – expensive sports car
• And two types of motorcycles: oBike – a standard two-wheeler motorcycle oTrike – a three-wheeler motorcycle
6. Create classes to represent Car and Motorcycle.
7. These classes must inherit from parent class Vehicle.
8. These vehicles must have following fields: ID, Name, Rental Price, Category, Type, IsReserved
9. Use your Java and object-oriented programming knowledge to create this hierarchy.
10. The application should keep track of available and reserved vehicles using the most appropriate generic collection.
11. Use LINQ to display all, available and reserved vehicles.
12. Your knowledge of object-oriented programming will play an important role in evaluation. • You will get higher grades if: Proper use of inheritance Interface is user-friendly
Used LINQ to display vehicles
App menu runs smoothly without crashing
Otherwise, there will be grade deductions.
13. The menu should run continuously until the user quits the application.
please find below code
main program
using System;
using System.Collections.Generic;
using System.Linq;
namespace A1fnamelname
{
class Program
{
static void Main(string[] args)
{
int ch;
var Car = new List<Car>();
var Moto = new List<Motorcycle>();
Car.Add(new Car("Name1", 1, 1000, "Hatchback", "oStandard"));
Car.Add(new Car("Name2", 2, 2000, "Sedan", "oStandard"));
Car.Add(new Car("Name3", 3, 3000, "SUV", "oExotic"));
Moto.Add(new Motorcycle("MName1", 1, 1000, "Cruiser", "oBike"));
Moto.Add(new Motorcycle("MName2", 2, 2000, "Sports", "oTrike "));
Moto.Add(new Motorcycle("MName3", 3, 3000, "Dirt", "oBike"));
do
{
menu();
ch = Convert.ToInt32(Console.ReadLine());
switch(ch)
{
case 1:
Console.WriteLine("Car");
var avlistt = (from s in Car
select s).ToList();
foreach (var cars in avlistt)
Console.WriteLine(cars);
Console.WriteLine("Motor Cycle");
var avlist = (from s in Moto
select s).ToList();
foreach (var cars in avlist)
Console.WriteLine(cars);
break;
case 2:
Console.WriteLine("Car");
avlistt = (from s in Car
where s.IsReserve() == false
select s).ToList();
foreach (var cars in avlistt)
{
Console.WriteLine(cars);
}
Console.WriteLine("Motor Cycle");
avlist = (from s in Moto
where s.IsReserve() == false
select s).ToList();
foreach (var cars in avlist)
{
Console.WriteLine(cars);
}
break;
case 3:
Console.WriteLine("Car");
avlistt = (from s in Car
where s.IsReserve() == true
select s).ToList();
foreach (var cars in avlistt)
{
Console.WriteLine(cars);
}
Console.WriteLine("Motor Cycle");
avlist = (from s in Moto
where s.IsReserve() == true
select s).ToList();
foreach (var cars in avlist)
{
Console.WriteLine(cars);
}
break;
case 4:
Console.WriteLine("Reserve vehicle");
Console.WriteLine("Please select Vehicle \n 1. Car \n2. MotoCycle");
int vc = Convert.ToInt32(Console.ReadLine());
Console.Write("Available Vehicles are: ");
if (vc==1)
{
avlistt = (from s in Car
where s.IsReserve() == false
select s).ToList();
foreach(var cars in avlistt)
{
Console.WriteLine(cars);
}
Console.WriteLine("Please Enter ID");
int id = Convert.ToInt32(Console.ReadLine());
foreach (var cars in avlistt)
{
if (cars.GetID() == id)
{
cars.setReserve();
}
}
}
else
{
avlist = (from s in Moto
where s.IsReserve() == false
select s).ToList();
foreach (var cars in avlist)
{
Console.WriteLine(cars);
}
Console.WriteLine("Please Enter ID");
int id = Convert.ToInt32(Console.ReadLine());
foreach (var cars in avlist)
{
if (cars.GetID() == id)
{
cars.setReserve();
}
}
}
break;
case 5:
Console.WriteLine("Please select Vehicle \n 1. Car \n2. MotoCycle");
vc = Convert.ToInt32(Console.ReadLine());
if (vc == 1)
{
avlistt = (from s in Car
where s.IsReserve() == false
select s).ToList();
Console.WriteLine("Please Enter ID");
int id = Convert.ToInt32(Console.ReadLine());
foreach (var cars in avlistt)
{
if (cars.GetID() == id)
{
cars.CancelReserve();
}
}
}
else
{
avlist = (from s in Moto
where s.IsReserve() == false
select s).ToList();
Console.WriteLine("Please Enter ID");
int id = Convert.ToInt32(Console.ReadLine());
foreach (var cars in avlist)
{
if (cars.GetID() == id)
{
cars.CancelReserve();
}
}
}
break;
}
} while (ch != 6);
}
public static void menu()
{
Console.WriteLine("Enter your option");
Console.WriteLine("1: View all vehicle");
Console.WriteLine("2: View available vehicles");
Console.WriteLine("3: View reserved vehicles");
Console.WriteLine("4: Reserve a vehicle");
Console.WriteLine("5: Cancel reservation ");
Console.WriteLine("6: Exit");
}
}
}
car class
using System;
using System.Collections.Generic;
using System.Text;
namespace A1fnamelname
{
class Car : Vehicle
{
public Car(string Name, int ID, double Price, string Category, string Type) : base(Name, Price, Category, Type,ID)
{
}
}
}
Motorcycle class
using System;
using System.Collections.Generic;
using System.Text;
namespace A1fnamelname
{
public class Motorcycle : Vehicle
{
public Motorcycle(string Name, int ID, double Price, string Category, string Type):base(Name, Price, Category, Type,ID)
{
}
}
}
Vehicle class
using System;
using System.Collections.Generic;
using System.Text;
namespace A1fnamelname
{
public class Vehicle
{
string Name;
int ID;
double Price;
string Category;
string Type;
bool IsReserved;
public Vehicle(string Name, double Price,string Category ,string Type,int ID)
{
this.Name = Name;
this.ID = ID;
this.Price = Price;
this.Category = Category;
this.Type = Type;
this.IsReserved = false;
}
public void setReserve()
{
this.IsReserved = true;
}
public void CancelReserve()
{
this.IsReserved = false;
}
public bool IsReserve()
{
return IsReserved;
}
public int GetID()
{
return this.ID;
}
override public string ToString()
{
string outp = String.Empty;
outp += "ID: "+ID+"\t"+"Name :"+ Name + "\t" + "Rental price: " + Price +"\t"+ "Category: " + Category+"\t" + "Type: " + Type;
return outp;
}
}
}
output