Destination class: Parse/TryParse methods Add 2 methods to the Destination class. These methods will receive a string co

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

Destination class: Parse/TryParse methods Add 2 methods to the Destination class. These methods will receive a string co

Post by answerhappygod »

Destination class: Parse/TryParse methods
Add 2 methods to the Destination class. These methods willreceive a string consisting of comma separated values. The stringrepresents a single instance of a Destination. The givenDestination class code is valid and does not need to bealtered.
The Parse method will break the string apart and return aninstance of Destination.
The TryParse method will receive a string representing aninstance of Destination. The method will return a boolean valueindicating a successful creation of a Destination instance. Themethod out parameter will return the Destination instance of theparsed string. DO NOT include atry/catch in the method.
CODE
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;
namespace Assessment{ public class Destination { public string Location { get; privateset; } public DateTime VisitDate { get;private set; }
public Destination (stringlocation, DateTime visitDate) { if(string.IsNullOrWhiteSpace(location)) { throw newArgumentNullException("Location is required"); } Location=location; VisitDate=visitDate; }
public override stringToString() { return$"{Location},{VisitDate}"; }
//TODO 1: Create Parse() andTryParse() methods }}
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply