Skip to content
Permalink
67d5c9d2c5
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
88 lines (74 sloc) 2.63 KB
using System;
using System.Collections.Generic;
using System.Linq;
namespace VehicleInventory
{
class Program
{
static void Main(string[] args)
{
string filepath = @"/Volumes/krb11010/3220/CarInventory-Complete/VehicleInventory.csv";
List<Car> cars = FileHelper.GetCars(filepath);
while (true)
{
Console.Clear();
Console.WriteLine("Input the number for what you're trying to search by:");
Console.WriteLine("1 - Search by manufacturer");
Console.WriteLine("2 - Search by year");
Console.WriteLine("3 - Search by mileage range");
Console.WriteLine("4 - Search by price range");
Console.WriteLine("10 - Exit");
string action = Console.ReadLine();
List<Car> searchResult = new List<Car>();
switch (action)
{
case "1":
Console.WriteLine("What vehicle manufacturer is the customer interested in?");
string make = Console.ReadLine();
searchResult = cars.Where(w => w.Make == make).ToList();
break;
case "2":
Console.WriteLine("What year vehicle is the customer interested in?");
double year = Convert.ToDouble(Console.ReadLine());
searchResult = cars.Where(w => w.Year == year).ToList();
break;
case "3":
Console.WriteLine("What is the minimum number of acceptable miles?");
double mileMinimum = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("What is the maximum number of acceptable miles?");
double mileMaximum = Convert.ToDouble(Console.ReadLine());
searchResult = cars.Where(w => w.Mileage >= mileMinimum && w.Mileage <= mileMaximum).ToList();
break;
case "4":
Console.WriteLine("What is the minimum price the customer wants to pay?");
decimal priceMinimum = Convert.ToDecimal(Console.ReadLine());
Console.WriteLine("What is the maximum price the customer wants to pay?");
decimal priceMaximum = Convert.ToDecimal(Console.ReadLine());
searchResult = cars.Where(w => w.Price >= priceMinimum && w.Price <= priceMaximum).ToList();
break;
case "10":
Environment.Exit(0);
break;
default:
Console.WriteLine("Please input a valid response. Hit return to try again...");
Console.ReadLine();
continue; // Start over, don't display results
}
if (searchResult.Count > 0)
{
Console.Clear();
Console.WriteLine("Search Results");
Console.WriteLine();
foreach (Car car in searchResult)
{
Console.WriteLine(car.GetDetails());
}
Console.WriteLine();
Console.WriteLine("Press return to search again");
Console.ReadLine();
}
// else No results, try again
}
}
}
}