Add code to the supplied Add Destination(Destination site) method to check that a) the parameter has a value and b) the

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Add code to the supplied Add Destination(Destination site) method to check that a) the parameter has a value and b) the

Post by answerhappygod »

Add code to the supplied Add Destination(Destination site)method to check that a) the parameter has a valueand b) the destination site does not already exist on thelist of sites for the Tour. The Location and Visit date combinationmust be unique. Example: St. John NS on Jun 122022 is different than St. John NS on Jun 132022; Charlett Town NS on Aug 12 2022 isdifferent than St. John NS on Aug 12 2022.However: St. John NS on Jun 12 2022 is the sameas St. John NS on Jun 12 2022. If the destinationpasses both validations, add to the list of Sites.
Remove Destination
Add code to the supplied Remove Destination(Destination site)method to check that a) the parameter has a valueand b) the destination site exists on the list of sitesfor the Tour. The Location and Visit date submitted must match thedestination exactly to be removed. Remove the destination from thelist of Sites if a match was found.
CODE
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;
namespace Assessment{ public class Tour { private string _Name; public string Name { get { return _Name;} set { if(string.IsNullOrWhiteSpace(value)) throw new ArgumentNullException("Tour name required"); _Name =value.Trim(); } } public TourType Type { get; set; }
public Transport Vehicle { get;private set; }
public List<Destination> Sites{ get; private set; }
public int Duration { get { if(Sites.Count > 1) { bool found = false; DateTime date1 = Sites[0].VisitDate; foreach(var item in Sites) { if (item.VisitDate != date1) { found = true; } } if (!found) { return 1; } else { return (Sites[Sites.Count - 1].VisitDate -Sites[0].VisitDate).Days; } } else if(Sites.Count == 1) return 1; else return 0; } }
public Tour(string name, TourTypetype, Transport vehicle, List<Destination> sites) { Name=name; Type=type; Vehicle=vehicle; if (sites == null) { Sites = newList<Destination>(); } else { Sites=sites; } }
//TODO 2: Add a Destination public void AddDestination(Destinationsite) { // add your codehere }
//TODO 3: Remove a Destination
public voidRemoveDestination(Destination site) { //add your codehere } }}
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply