using System;
namespace Warehouse
{
class Program
{
static void Main(string[] args)
{
string _username = "Joker";
string _password = "WhySoSeri0s";
Console.WriteLine("Please provide username to access the BrandX system");
string username = Console.ReadLine();
Console.WriteLine("Please provide password");
string password = Console.ReadLine();
if (username == _username && password == _password)
{
CarStock carstock = new CarStock(76);
//not sure if the program should work as is, or after the user writes an
option and it returns a value, the program should list the remaining options for the
user? I did it as the assignment says, so it exits after each completed option.
Console.WriteLine("Please select the action.");
Console.WriteLine("1. Show stock count");
Console.WriteLine("2. Show total value of all cars in stock");
Console.WriteLine("3. Register one car sold");
Console.WriteLine("4. Get stock status");
string input = Console.ReadLine();
//tryparse is used because it will return false if the variable is wrong
(I first tried only with int.Parse, and then I did a google search)
bool success = Int32.TryParse(input, out int option);
if (success == false)
{
Console.WriteLine("Invalid operation: " + input);
Environment.Exit(0);
}
if (option == 1)
{
Console.WriteLine(carstock.GetStockCount());
}
else if (option == 2)
{
Console.WriteLine(carstock.GetTotalValue());
}
else if (option == 3)
{
carstock.OneCarSold();
Console.WriteLine(carstock.GetStockCount());
}
else if (option == 4)
{
Console.WriteLine(carstock.GetStockStatus());
}
else
{
Console.WriteLine("Invalid operation: " + input);
}
Environment.Exit(0);
}
else
{
Console.WriteLine("You are not authorized to access this service");
Environment.Exit(0);
}
}
}
class CarStock
{
public string TypeName { get; set; }
public int Price { get; set; }
public int TotalInStock { get; set; }
public CarStock(int initStock)
{
TotalInStock = initStock;
Price = 70000;
TypeName = "CarX";
}
public int GetStockCount()
{
return TotalInStock;
}
public int GetTotalValue()
{
return TotalInStock * Price;
}
public void OneCarSold()
{
//TotalInStock = TotalInStock - 1; - maybe this way is better and clearer
than --?
TotalInStock--;
}
public string GetStockStatus()
{
//in the assignment it doesn’t say “below 10 cars” or “less or equal to 10 cars”
but I made it so 10 is included in the quantity, otherwise, if it was < 10, and the
number of total stock is 10, the program will give an error
if (TotalInStock <= 10)
{
return "veryLow";
}
else if (TotalInStock <= 25)
{
return "Low";
}
else if (TotalInStock <= 100)
{
return "Normal";
}
else
{
return "Over";
}
}