static void Main(string[] args) { var tollCalc = new TollCalculator(); var car = new Car(); var taxi = new Taxi(); var bus = new Bus(); var truck = new DeliveryTruck(); Console.WriteLine($"The toll for a car is {tollCalc.CalculateToll(car)}"); Console.WriteLine($"The toll for a taxi is {tollCalc.CalculateToll(taxi)}"); Console.WriteLine($"The toll for a bus is {tollCalc.CalculateToll(bus)}"); Console.WriteLine($"The toll for a truck is {tollCalc.CalculateToll(truck)}"); try { tollCalc.CalculateToll("this will fail"); } catch (ArgumentException e) { Console.WriteLine("Caught an argument exception when using the wrong type"); } try { tollCalc.CalculateToll(null); } catch (ArgumentNullException e) { Console.WriteLine("Caught an argument exception when using null"); } }
public void GetCombinations_SmallTest() { int N = 3; int M = 2; List <List <int> > expected = new List <List <int> >() { new List <int>() { 0, 1 }, new List <int>() { 0, 2 }, new List <int>() { 1, 0 }, new List <int>() { 1, 2 }, new List <int>() { 2, 0 }, new List <int>() { 2, 1 } }; Assert.IsTrue(TestHelpers.DoesListContainSameLists(expected, DeliveryTruck.GetOrderedCombinations(N, M))); }
static void TestVehicleType() { #region Patterns_VehicleType var tollCalc = new TollCalculatorV1(); var car = new Car(); var taxi = new Taxi(); var bus = new Bus(); var truck = new DeliveryTruck(); Console.WriteLine($"The toll for a car is {tollCalc.CalculateToll(car)}"); Console.WriteLine($"The toll for a taxi is {tollCalc.CalculateToll(taxi)}"); Console.WriteLine($"The toll for a bus is {tollCalc.CalculateToll(bus)}"); Console.WriteLine($"The toll for a truck is {tollCalc.CalculateToll(truck)}"); try { tollCalc.CalculateToll("this will fail"); } catch (ArgumentException) { Console.WriteLine("Caught an argument exception when using the wrong type"); } try { tollCalc.CalculateToll(null); } catch (ArgumentNullException) { Console.WriteLine("Caught an argument exception when using null"); } #endregion }
public void SpawnDeliveryTruck(DeliveryEvent deliveryEvent) { Order order = deliveryEvent.order; Database db = GameObject.Find("Database").GetComponent <Database>(); GameObject deliveryTruck = Instantiate(db.GetStoreObject("Delivery Truck 1").gameObject_); DeliveryTruck truck = deliveryTruck.GetComponent <DeliveryTruck>(); order.deliveryTruck = truck; truck.order = order; truck.manager = this; truck.leftSideText.text = order.vendor.vendorName; truck.rightSideText.text = order.vendor.vendorName; deliveryTruck.transform.position = truckLocation.transform.position; deliveryTruck.transform.eulerAngles = truckLocation.transform.eulerAngles; List <Box> deliveryBoxes = gameObject.GetComponent <Inventory>().BoxProducts(order); truck.boxes = deliveryBoxes; deliveries.Add(new Delivery(order, truck)); // UI UIManager_v5 uiManager = GameObject.Find("UIManager").GetComponent <UIManager_v5>(); uiManager.CreateDeliveryNotification(truck); uiManager.leftBarDeliveryPanel.AddDelivery(order); }
private void ApplyGetResultTest(int locationsCount, int[,] locations, int stopsCount, List <List <int> > expected) { DeliveryTruck calculator = new DeliveryTruck(locationsCount, locations, stopsCount); List <List <int> > result = calculator.GetResult(); Assert.AreEqual(expected, result); }
public static void Run() { Car c1 = new Car() { Passengers = 2 }; Car c2 = new Car() { Passengers = 3 }; Taxi t1 = new Taxi(); Bus b1 = new Bus(); DeliveryTruck d1 = new DeliveryTruck(); Console.WriteLine($"CalculateTollByType ({c1.GetType()}): " + CalculateTollByType(c1)); Console.WriteLine($"CalculateTollByType ({b1.GetType()}): " + CalculateTollByType(b1)); Console.WriteLine($"CalculateTollByType ({d1.GetType()}): " + CalculateTollByType(d1)); Console.WriteLine($"CalculateTollByProperty ({c1.GetType()}): " + CalculateTollByProperty(c1)); Console.WriteLine($"CalculateTollByProperty ({c2.GetType()}): " + CalculateTollByProperty(c2)); Console.WriteLine($"CalculateTollByProperty ({b1.GetType()}): " + CalculateTollByProperty(b1)); Console.WriteLine($"CalculateTollByProperty ({d1.GetType()}): " + CalculateTollByProperty(d1)); }
public void FleetTest() { IDeliveryVehicle deliveryBike = new DeliveryBike(); IDeliveryVehicle deliveryCar = new DeliveryCar(); IDeliveryVehicle deliveryVan = new DeliveryVan(); IDeliveryVehicle deliveryTruck = new DeliveryTruck(); Fleet fleetOfVehicles = new Fleet(); fleetOfVehicles.Add(deliveryBike); fleetOfVehicles.Add(deliveryCar); fleetOfVehicles.Add(deliveryVan); fleetOfVehicles.Add(deliveryTruck); StringWriter writer = beginReading(); // begin console capture MakeDelivery(fleetOfVehicles); List <String> consoleEntries = endReading(writer); // end console capture var expectedList = new List <string>(new [] { "Bike makes a delivery", "Car makes a delivery", "Van makes a delivery", "Truck makes a delivery" }); Assert.AreEqual(consoleEntries.Count, 4, "Delivery count does not match expected deliveries"); CollectionAssert.AreEqual(consoleEntries, expectedList, "Deliveries don't match expected deliveries"); }
void OnTriggerExit(Collider other) { //truck's gone, forget about it if (other.gameObject.CompareTag("DeliveryTruck")) { truck = null; receivingPizzas = false; } }
public static void Demo() { var soloDriver = new Car(); var twoRideShare = new Car { Passengers = 1 }; var threeRideShare = new Car { Passengers = 2 }; var fullVan = new Car { Passengers = 5 }; var emptyTaxi = new Taxi(); var signleFare = new Taxi { Fares = 1 }; var doubleFare = new Taxi { Fares = 2 }; var fullVanPool = new Taxi { Fares = 5 }; var lowOccupantBus = new Bus { Capacity = 90, Riders = 15 }; var normalBus = new Bus { Capacity = 90, Riders = 75 }; var fullBus = new Bus { Capacity = 90, Riders = 85 }; var heavyTruck = new DeliveryTruck { GrossWeightClass = 7500 }; var truck = new DeliveryTruck { GrossWeightClass = 4000 }; var lightTruck = new DeliveryTruck { GrossWeightClass = 2500 }; Console.WriteLine($"혼자 타고 있는 차의 톨요금은 {CalculateToll(soloDriver)}"); Console.WriteLine($"두명이 타고 있는 차의 톨요금은 {CalculateToll(twoRideShare)}"); Console.WriteLine($"세명이 타고 있는 차의 톨요금은 {CalculateToll(threeRideShare)}"); Console.WriteLine($"꽉 차있는 차의 요금은 {CalculateToll(fullVan)}"); Console.WriteLine($"빈 택시의 요금은 {CalculateToll(emptyTaxi)}"); Console.WriteLine($"한명이 타고 있는 택시의 톨요금은 {CalculateToll(signleFare)}"); Console.WriteLine($"둘이 타고 있는 택시의 톨요금은 {CalculateToll(doubleFare)}"); Console.WriteLine($"꽉 차있는 택시의 톨요금은 {CalculateToll(fullVanPool)}"); Console.WriteLine($"승객이 적은 버스의 톨요금은 {CalculateToll(lowOccupantBus)}"); Console.WriteLine($"승객이 적당한 버스의 톨요금은 {CalculateToll(normalBus)}"); Console.WriteLine($"승객이 많은 버스의 톨요금은 {CalculateToll(fullBus)}"); Console.WriteLine($"무거운 트럭의 톨요금은 {CalculateToll(heavyTruck)}"); Console.WriteLine($"트럭의 톨요금은 {CalculateToll(truck)}"); Console.WriteLine($"가벼운 차의 톨요금은 {CalculateToll(lightTruck)}"); }
void InitiatePizzaReception(DeliveryTruck receiver) { //make sure the truck is going slow enough to deliver pizzas if (receiver.GetComponent <Rigidbody>().velocity.magnitude < speedTolerance) { //it is! wait a sec, then drop the 'zas receivingPizzas = true; launchTimer = delayBeforeReceive; } }
private void btnDeliveryTruck_Click(object sender, RoutedEventArgs e) { var vehicle = new DeliveryTruck { GrossWeightClass = _random.Next(1000, 10000) }; var inbound = _random.NextBool(); TollSystem.AddEntry(vehicle, GenerateTimeStamp(), inbound, GenerateLicense()); }
void InitiatePizzaResupply(DeliveryTruck receiver) { //make sure the truck is going slow enough to receive pizzas if (receiver.GetComponent <Rigidbody>().velocity.magnitude < speedTolerance) { //it is! wait a sec, then drop the 'zas supplying = true; pizzasToGiveThisTrip = truck.getMaxPizzas() - truck.HowManyPizzas(); spawnTimer = delayBeforeResupply; } }
//public List<DeliveryNotification> deliveryNotifications = new List<DeliveryNotification>(); public void CreateDeliveryNotification(DeliveryTruck truck) { Image newImage = Instantiate(deliveryPopupPrefab) as Image; newImage.transform.SetParent(popupsParent.transform, false); //deliveryNotifications.Add(newImage.GetComponent<DeliveryNotification>()); DeliveryNotification notification = newImage.GetComponent <DeliveryNotification>(); notification.truck = truck; notification.SetButtonCallbacks(truck); }
public static void Demo() { var soloDriver = new Car(); // you have to add using statement var twoRideShare = new Car() { Passengers = 1 }; var threeRideShare = new Car { Passengers = 2 }; var fullVan = new Car { Passengers = 5 }; var emtyTaxi = new Taxi(); // add using statement var singleFare = new Taxi() { Fares = 1 }; var doubleFare = new Taxi() { Fares = 2 }; var fullVanPoolFare = new Taxi { Fares = 5 }; var lowOccupantBus = new Buss() { Capacity = 90, Riders = 15 }; var normalBus = new Buss() { Capacity = 90, Riders = 75 }; var fullBus = new Buss() { Capacity = 90, Riders = 85 }; var heavyTruck = new DeliveryTruck() { GrossWeightClass = 7500 }; var truck = new DeliveryTruck() { GrossWeightClass = 4000 }; var lightTruck = new DeliveryTruck() { GrossWeightClass = 2500 }; Console.WriteLine($"The toll for single driver is {CalculateToll(soloDriver)}"); }
public void GetLocationsIncludingOrigin_SmallTest() { int[,] locations = new int[, ] { }; int locationsCount = 0; int[,] expected = new int[, ] { { 0, 0 } };; Assert.IsTrue(TestHelpers.Are2DArraysEqual <int>(expected, DeliveryTruck.GetLocationsIncludingOrigin(locations, locationsCount))); }
private static void Main(string[] args) { var car = new Car(); //Try adding Passengers var taxi = new Taxi(); //Try adding Fares var bus = new Bus(); //Try adding Capacity and Riders var truck = new DeliveryTruck(); //Try adding GrossWeightClass Console.WriteLine($"The toll for a car is {TollCalculator.CalculateToll(car)}"); Console.WriteLine($"The toll for a taxi is {TollCalculator.CalculateToll(taxi)}"); Console.WriteLine($"The toll for a bus is {TollCalculator.CalculateToll(bus)}"); Console.WriteLine($"The toll for a truck is {TollCalculator.CalculateToll(truck)}"); Console.WriteLine("Are you inbound to or outbound from the city? Press I or O: "); ConsoleKey key = default; while (key != ConsoleKey.I && key != ConsoleKey.O) { key = Console.ReadKey(true).Key; } DateTime now = DateTime.Now; Console.WriteLine($"Riding " + $"{(key == ConsoleKey.I ? "inbound" : "outbound")} " + $"on a " + $"{now.DayOfWeek} " + $"at " + $"{now.TimeOfDay:hh\\:mm\\:ss} " + $"will increase your toll by " + $"{TollCalculator.PeakTimePremium(DateTime.Now, key == ConsoleKey.I)}x"); //try //{ // TollCalculator.CalculateToll("this will fail"); //} //catch (ArgumentException e) //{ // Console.WriteLine("Caught an argument exception when using the wrong type"); //} //try //{ // TollCalculator.CalculateToll(null!); //} //catch (ArgumentNullException e) //{ // Console.WriteLine("Caught an argument exception when using null"); //} var ages = TollCalculator.GetAge(); var name = ages.Item2; Console.WriteLine(name); }
public void GetLocationsIncludingOrigin_LargeTest() { int[,] locations = new int[, ] { { 1, 2 }, { 3, 4 }, { 5, 6 }, { 7, 8 }, }; int locationsCount = 4; int[,] expected = new int[, ] { { 0, 0 }, { 1, 2 }, { 3, 4 }, { 5, 6 }, { 7, 8 }, };; Assert.IsTrue(TestHelpers.Are2DArraysEqual <int>(expected, DeliveryTruck.GetLocationsIncludingOrigin(locations, locationsCount))); }
private static void MatchOne() { Console.WriteLine("TollFare"); var car = new Car(); var taxi = new Taxi(); var bus = new Bus(); var truck = new DeliveryTruck(); Console.WriteLine($"The toll for a car is {Matcher.TollFare(car)}"); Console.WriteLine($"The toll for a taxi is {Matcher.TollFare(taxi)}"); Console.WriteLine($"The toll for a bus is {Matcher.TollFare(bus)}"); Console.WriteLine($"The toll for a truck is {Matcher.TollFare(truck)}"); }
public void SetButtonCallbacks(DeliveryTruck truck) { if (dm == null) { Start(); } VendorManager manager = truck.manager; dm.truck = truck; dm.boxes = truck.boxes; Button[] buttons = buttonPanel.GetComponentsInChildren <Button>(); buttons[0].onClick.AddListener(() => manager.RejectOrder(truck.order)); buttons[1].onClick.AddListener(() => manager.GetComponent <DispensaryManager>().uiManagerObject.GetComponent <UIManager_v3>().CreateOrderPreviewPanel(truck.order)); buttons[2].onClick.AddListener(() => dm.StartReceivingShipment(truck)); }
public decimal CalculateToll(object vehicle) { // Price per vehicle type // ========== // Car -> 2$ // Taxi -> 3.50$ // Bus -> 5$ // Truck -> 10$ return(vehicle switch { Car c => 2.00m, Taxi t => 3.50m, Bus b => 5.00m, DeliveryTruck t => 10.00m, { } => throw new ArgumentException("Not a known vehicle type", nameof(vehicle)),
// Update is called once per frame void OnTriggerStay(Collider other) { //if there's a truck in the bay, start resupplying pizzas! if (other.gameObject.CompareTag("DeliveryTruck")) { truck = other.GetComponent <DeliveryTruck>(); //if the truck's already got enough pizzas, ignore it if (truck.HowManyPizzas() >= truck.getMaxPizzas()) { return; } if (supplying == false) { InitiatePizzaResupply(truck); } } }
void OnTriggerStay(Collider other) { //if there's a truck in the bay, start taking pizzas! if (other.gameObject.CompareTag("DeliveryTruck")) { truck = other.GetComponent <DeliveryTruck>(); //if the truck has no pizzas, ignore it if (truck.HowManyPizzas() == 0) { return; } if (receivingPizzas == false) { InitiatePizzaReception(truck); } } }
private static void MatchTwo() { Console.WriteLine("OccupancyTypeTollFare"); var car1 = new Car { PassengerCount = 2 }; var taxi1 = new Taxi { Fare = 0 }; var bus1 = new Bus { Capacity = 100, RidersCount = 30 }; var truck1 = new DeliveryTruck { Weight = 30000 }; Console.WriteLine($"The toll for a car is {Matcher.OccupancyTypeTollFare(car1)}"); Console.WriteLine($"The toll for a taxi is {Matcher.OccupancyTypeTollFare(taxi1)}"); Console.WriteLine($"The toll for a bus is {Matcher.OccupancyTypeTollFare(bus1)}"); Console.WriteLine($"The toll for a truck is {Matcher.OccupancyTypeTollFare(truck1)}"); }
public void CalculateTest() { var tollCalc = new TollCalculatorPassenger();//new TollCalculator(); var car = new Car { Passengers = 3 }; var taxi = new Taxi { Fares = 2 }; var bus = new Bus { Capacity = 50, Riders = 49 }; var truck = new DeliveryTruck(); Console.WriteLine($"The toll for a car is {tollCalc.CalculateToll(car)}"); Console.WriteLine($"The toll for a taxi is {tollCalc.CalculateToll(taxi)}"); Console.WriteLine($"The toll for a bus is {tollCalc.CalculateToll(bus)}"); Console.WriteLine($"The toll for a truck is {tollCalc.CalculateToll(truck)}"); try { tollCalc.CalculateToll("this will fail"); } catch (ArgumentException) { Console.WriteLine("Caught an argument exception when using the wrong type"); } try { tollCalc.CalculateToll(null); } catch (ArgumentNullException) { Console.WriteLine("Caught an argument exception when using null"); } }
void Start() { playerTruck = GameObject.FindObjectOfType <DeliveryTruck>(); lost = false; gameTimer = timer_max; deliveriesRemaining = 0; timeElapsedThisGame = 0f; LoadLeaderboard(); //foreach (GameRecord g in gameRecords) //print(g.GetDescription()); possibleDeliveries = new List <GameObject>(); pizzaDeliveries = new List <PizzaDelivery>(); enemies = new List <GameObject>(); //get each possible delivery and add it to a list, and add a number of deliveries at random using the possibilities foreach (GameObject poss in GameObject.FindGameObjectsWithTag("PossibleDelivery")) { possibleDeliveries.Add(poss); } for (int i = 0; i < deliveriesToSpawn; i++) { GameObject poss = possibleDeliveries[Random.Range(0, possibleDeliveries.Count - 1)]; possibleDeliveries.Remove(poss); PizzaDelivery newPD = Instantiate(pizzaDeliveryPrefab, poss.transform.position, poss.transform.rotation) as PizzaDelivery; //newPD.launchTarget.position = poss.GetComponent<PossibleDelivery>().GetLaunchPosition(); newPD.pizzasOrdered = Random.Range(1, 5); pizzaDeliveries.Add(newPD); deliveriesRemaining++; } cash = 0; enemySpawnCounter = enemySpawnInterval; }
static void Main(string[] args) { /* First set of test code */ var tollCalc = new TollCalculator(); var car = new Car(); var taxi = new Taxi(); var bus = new Bus(); var truck = new DeliveryTruck(); Console.WriteLine($"The toll for a car is {tollCalc.CalculateToll(car)}"); Console.WriteLine($"The toll for a taxi is {tollCalc.CalculateToll(taxi)}"); Console.WriteLine($"The toll for a bus is {tollCalc.CalculateToll(bus)}"); Console.WriteLine($"The toll for a truck is {tollCalc.CalculateToll(truck)}"); try { tollCalc.CalculateToll("this will fail"); } catch (ArgumentException e) { Console.WriteLine("Caught an argument exception when using the wrong type"); Console.WriteLine($"{e.Message}"); } try { tollCalc.CalculateToll(null); } catch (ArgumentNullException e) { Console.WriteLine("Caught an argument exception when using null"); Console.WriteLine($"{e.Message}"); } /* 2nd test (after adding for occupants) * var tollCalc = new TollCalculator(); * * var soloDriver = new Car(); * var twoRideShare = new Car { Passengers = 1 }; * var threeRideShare = new Car { Passengers = 2 }; * var fullVan = new Car { Passengers = 5 }; * var emptyTaxi = new Taxi(); * var singleFare = new Taxi { Fares = 1 }; * var doubleFare = new Taxi { Fares = 2 }; * var fullVanPool = new Taxi { Fares = 5 }; * var lowOccupantBus = new Bus { Capacity = 90, Riders = 15 }; * var normalBus = new Bus { Capacity = 90, Riders = 75 }; * var fullBus = new Bus { Capacity = 90, Riders = 85 }; * * var heavyTruck = new DeliveryTruck { GrossWeightClass = 7500 }; * var truck = new DeliveryTruck { GrossWeightClass = 4000 }; * var lightTruck = new DeliveryTruck { GrossWeightClass = 2500 }; * * Console.WriteLine($"The toll for a solo driver is {tollCalc.CalculateToll(soloDriver)}"); * Console.WriteLine($"The toll for a two ride share is {tollCalc.CalculateToll(twoRideShare)}"); * Console.WriteLine($"The toll for a three ride share is {tollCalc.CalculateToll(threeRideShare)}"); * Console.WriteLine($"The toll for a fullVan is {tollCalc.CalculateToll(fullVan)}"); * * Console.WriteLine($"The toll for an empty taxi is {tollCalc.CalculateToll(emptyTaxi)}"); * Console.WriteLine($"The toll for a single fare taxi is {tollCalc.CalculateToll(singleFare)}"); * Console.WriteLine($"The toll for a double fare taxi is {tollCalc.CalculateToll(doubleFare)}"); * Console.WriteLine($"The toll for a full van taxi is {tollCalc.CalculateToll(fullVanPool)}"); * * Console.WriteLine($"The toll for a low-occupant bus is {tollCalc.CalculateToll(lowOccupantBus)}"); * Console.WriteLine($"The toll for a regular bus is {tollCalc.CalculateToll(normalBus)}"); * Console.WriteLine($"The toll for a bus is {tollCalc.CalculateToll(fullBus)}"); * * Console.WriteLine($"The toll for a truck is {tollCalc.CalculateToll(heavyTruck)}"); * Console.WriteLine($"The toll for a truck is {tollCalc.CalculateToll(truck)}"); * Console.WriteLine($"The toll for a truck is {tollCalc.CalculateToll(lightTruck)}"); * * try * { * tollCalc.CalculateToll("this will fail"); * } * catch (ArgumentException e) * { * Console.WriteLine("Caught an argument exception when using the wrong type"); * } * try * { * tollCalc.CalculateToll(null); * } * catch (ArgumentNullException e) * { * Console.WriteLine("Caught an argument exception when using null"); * } */ /* * Console.WriteLine("Testing the time premiums"); * * var testTimes = new DateTime[] * { * new DateTime(2019, 3, 4, 8, 0, 0), // morning rush * new DateTime(2019, 3, 6, 11, 30, 0), // daytime * new DateTime(2019, 3, 7, 17, 15, 0), // evening rush * new DateTime(2019, 3, 14, 03, 30, 0), // overnight * * new DateTime(2019, 3, 16, 8, 30, 0), // weekend morning rush * new DateTime(2019, 3, 17, 14, 30, 0), // weekend daytime * new DateTime(2019, 3, 17, 18, 05, 0), // weekend evening rush * new DateTime(2019, 3, 16, 01, 30, 0), // weekend overnight * }; * * foreach (var time in testTimes) * { * Console.WriteLine($"Inbound premium at {time} is {tollCalc.PeakTimePremiumFull(time, true)}"); * Console.WriteLine($"Outbound premium at {time} is {tollCalc.PeakTimePremiumFull(time, false)}"); * } * Console.WriteLine("===================================================="); * foreach (var time in testTimes) * { * Console.WriteLine($"Inbound premium at {time} is {tollCalc.PeakTimePremium(time, true)}"); * Console.WriteLine($"Outbound premium at {time} is {tollCalc.PeakTimePremium(time, false)}"); * } */ }
static void TestOccupancy(string regionName) { ITollCalculator tollCalc = regionName switch { "Pattern_CarTaxiOccupancy" => new TollCalculatorV2() as ITollCalculator, "Pattern_BusOccupancy" => new TollCalculatorV3() as ITollCalculator, "Pattern_DeliveryTruckWeight" => new TollCalculatorV4() as ITollCalculator, "Pattern_ChainedPatterns" => new TollCalculatorV5() as ITollCalculator, _ => new TollCalculatorV1() as ITollCalculator, }; var soloDriver = new Car(); var twoRideShare = new Car { Passengers = 1 }; var threeRideShare = new Car { Passengers = 2 }; var fullVan = new Car { Passengers = 5 }; var emptyTaxi = new Taxi(); var singleFare = new Taxi { Fares = 1 }; var doubleFare = new Taxi { Fares = 2 }; var fullVanPool = new Taxi { Fares = 5 }; var lowOccupantBus = new Bus { Capacity = 90, Riders = 15 }; var normalBus = new Bus { Capacity = 90, Riders = 75 }; var fullBus = new Bus { Capacity = 90, Riders = 85 }; var heavyTruck = new DeliveryTruck { GrossWeightClass = 7500 }; var truck = new DeliveryTruck { GrossWeightClass = 4000 }; var lightTruck = new DeliveryTruck { GrossWeightClass = 2500 }; Console.WriteLine($"The toll for a solo driver is {tollCalc.CalculateToll(soloDriver)}"); Console.WriteLine($"The toll for a two ride share is {tollCalc.CalculateToll(twoRideShare)}"); Console.WriteLine($"The toll for a three ride share is {tollCalc.CalculateToll(threeRideShare)}"); Console.WriteLine($"The toll for a fullVan is {tollCalc.CalculateToll(fullVan)}"); Console.WriteLine($"The toll for an empty taxi is {tollCalc.CalculateToll(emptyTaxi)}"); Console.WriteLine($"The toll for a single fare taxi is {tollCalc.CalculateToll(singleFare)}"); Console.WriteLine($"The toll for a double fare taxi is {tollCalc.CalculateToll(doubleFare)}"); Console.WriteLine($"The toll for a full van taxi is {tollCalc.CalculateToll(fullVanPool)}"); Console.WriteLine($"The toll for a low-occupant bus is {tollCalc.CalculateToll(lowOccupantBus)}"); Console.WriteLine($"The toll for a regular bus is {tollCalc.CalculateToll(normalBus)}"); Console.WriteLine($"The toll for a bus is {tollCalc.CalculateToll(fullBus)}"); Console.WriteLine($"The toll for a truck is {tollCalc.CalculateToll(heavyTruck)}"); Console.WriteLine($"The toll for a truck is {tollCalc.CalculateToll(truck)}"); Console.WriteLine($"The toll for a truck is {tollCalc.CalculateToll(lightTruck)}"); try { tollCalc.CalculateToll("this will fail"); } catch (ArgumentException) { Console.WriteLine("Caught an argument exception when using the wrong type"); } try { tollCalc.CalculateToll(null !); } catch (ArgumentNullException) { Console.WriteLine("Caught an argument exception when using null"); } }
public Delivery(Order order_, DeliveryTruck truck_) { order = order_; truck = truck_; }
public static void Demo(int version) { Version = version; var soloDriver = new Car(); var twoRideShare = new Car { Passengers = 1 }; var threeRideShare = new Car { Passengers = 2 }; var fullVan = new Car { Passengers = 5 }; var emptyTaxi = new Taxi(); var singleFare = new Taxi { Fares = 1 }; var doubleFare = new Taxi { Fares = 2 }; var fullValPool = new Taxi { Fares = 5 }; var lowOccupantBus = new Bus { Capacity = 90, Riders = 15 }; var normalBus = new Bus { Capacity = 90, Riders = 75 }; var fullBus = new Bus { Capacity = 90, Riders = 85 }; var lightTruck = new DeliveryTruck { GrossWeightClass = 2500 }; var truck = new DeliveryTruck { GrossWeightClass = 4000 }; var heavyTruck = new DeliveryTruck { GrossWeightClass = 7500 }; Console.WriteLine($"The toll for a {nameof(soloDriver)} is {CalculateToll(soloDriver)}"); Console.WriteLine($"The toll for a {nameof(twoRideShare)} is {CalculateToll(twoRideShare)}"); Console.WriteLine($"The toll for a {nameof(threeRideShare)} is {CalculateToll(threeRideShare)}"); Console.WriteLine($"The toll for a {nameof(fullVan)} is {CalculateToll(fullVan)}"); Console.WriteLine($"The toll for a {nameof(emptyTaxi)} is {CalculateToll(emptyTaxi)}"); Console.WriteLine($"The toll for a {nameof(singleFare)} is {CalculateToll(singleFare)}"); Console.WriteLine($"The toll for a {nameof(doubleFare)} is {CalculateToll(doubleFare)}"); Console.WriteLine($"The toll for a {nameof(fullValPool)} is {CalculateToll(fullValPool)}"); Console.WriteLine($"The toll for a {nameof(lowOccupantBus)} is {CalculateToll(lowOccupantBus)}"); Console.WriteLine($"The toll for a {nameof(normalBus)} is {CalculateToll(normalBus)}"); Console.WriteLine($"The toll for a {nameof(fullBus)} is {CalculateToll(fullBus)}"); Console.WriteLine($"The toll for a {nameof(lightTruck)} is {CalculateToll(lightTruck)}"); Console.WriteLine($"The toll for a {nameof(truck)} is {CalculateToll(truck)}"); Console.WriteLine($"The toll for a {nameof(heavyTruck)} is {CalculateToll(heavyTruck)}"); try { CalculateToll("This will fail"); } catch (ArgumentException) { Console.WriteLine("Caught an argument exception when using the wrong type"); } try { CalculateToll(null); } catch (ArgumentException) { Console.WriteLine("Caught an argument exception when using null"); } }
public void Start() { truck = GameObject.FindObjectOfType <DeliveryTruck>(); }