Created
May 24, 2022 17:04
-
-
Save luiseduardohd/1c4cd964b089c380f55270061539ee48 to your computer and use it in GitHub Desktop.
United Rentals Interview code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using Newtonsoft.Json; | |
namespace Test1 | |
{ | |
class MainClass | |
{ | |
public static void Main(string[] args) | |
{ | |
Console.WriteLine("Start"); | |
var orders = new List<Order>() { | |
new Order(){ | |
Num = "1", | |
CustomerNum = "C1", | |
OrderDate = DateTime.Now, | |
OrderDetails = new List<OrderDetail>(){ | |
new OrderDetail() | |
{ | |
ItemNum = "01", | |
ItemDescr = "Desc1", | |
Quantity = 1, | |
Price = 1, | |
} | |
}, | |
}, | |
new Order(){ | |
Num = "2", | |
CustomerNum = "C2", | |
OrderDate = DateTime.Now, | |
OrderDetails = new List<OrderDetail>(){ | |
new OrderDetail() | |
{ | |
ItemNum = "02", | |
ItemDescr = "Desc2", | |
Quantity = 2, | |
Price = 2, | |
} | |
}, | |
}, | |
new Order(){ | |
Num = "3", | |
CustomerNum = "C3", | |
OrderDate = DateTime.Now, | |
OrderDetails = new List<OrderDetail>(){ | |
}, | |
}, | |
}; | |
bool isANumber = false; | |
int number; | |
do | |
{ | |
Console.WriteLine("Please enter the order number:"); | |
var input = Console.ReadLine(); | |
isANumber = Int32.TryParse(input, out number); | |
if (!isANumber) | |
Console.WriteLine("Please enter a valid number"); | |
} | |
while ( ! isANumber ); | |
var ordersFinded = orders.FindAll(o => o.Num == "" + number); | |
if (ordersFinded.Count == 0) | |
{ | |
Console.WriteLine("There is no order with that number"); | |
Console.WriteLine($"Choose a number between: {orders.Min( o => Int32.Parse(o.Num) ) } and : {orders.Max(o => Int32.Parse(o.Num)) }"); | |
} | |
foreach(var o in ordersFinded) | |
{ | |
Console.WriteLine(JsonConvert.SerializeObject(o)); | |
if( o.OrderDetails == null || o.OrderDetails.Count == 0) | |
{ | |
Console.WriteLine("There is no order details for this order"); | |
} | |
} | |
Console.WriteLine("End"); | |
Console.ReadLine(); | |
} | |
} | |
class Order | |
{ | |
public string Num { get; set; } | |
public string CustomerNum { get; set; } | |
public DateTime OrderDate { get; set; } | |
public IList<OrderDetail> OrderDetails { get; set; } | |
} | |
class OrderDetail | |
{ | |
public string ItemNum { get; set; } | |
public string ItemDescr { get; set; } | |
public int Quantity { get; set; } | |
public decimal Price { get; set; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
.NET Interview Test - Instructions
from Nataliia Biernikova (internal) to Luis Hernandez (privately): 1:15 PM
.NET Interview Test - Instructions
Task
Create a Console application using one of the following environment options, to address the following requirements.
Environment Set up
Option 1: Open Visual Studio or Visual Studio Code – will provide the best user experience.
Option 2: dotnetfiddle – no intellisense, but will provide error messages.
https://dotnetfiddle.net.
Option 3: onlinegdb – has some intellisense, but no details on error messages.
https://www.onlinegdb.com/online_csharp_compiler
Requirements
Create a console application that does the following:
Initial Code snipit – The Order Object
public class Order {
public string Num { get; set; }
public string CustomerNum { get; set; }
public DateTime OrderDate { get; set; }
public IList OrderDetails { get; set; }
}
public class OrderDetail {
public string ItemNum { get; set; }
public string ItemDescr { get; set; }
public int Quantity { get; set; }
public decimal Price { get; set; }
}