Question
Please help with this .class C# Need help validating that the entered state is valid Program the Address class, to validate the states, throw ArgumentException
Please help with this .class C#
Need help validating that the entered state is valid Program the Address class, to validate the states, throw ArgumentException if state entered in the constructor aren't in the list be sure to catch the ArgumentException for a bad state value.
class Address { private string street; private string city; private string state; private string zip;
public string Street { get; set; } public string City { get; set; } public string Zip { get; set; }
public string State { get { return state; } set { string[] states = { "Alabama", "Alaska", "Arizona", " Arkansas", " California", " Colorado", " Connecticut", " Delaware", " Florida", " Georgia", " Hawaii", " Idaho", " Illinois", " Indiana", " Iowa", " Kansas", " Kentucky", " Louisiana", " Maine", " Maryland", " Massachusetts", " Michigan", " Minnesota", " Mississippi", " Missouri", " Montana", " Nebraska", " Nevada", " New", " Hampshire", " New Jersey", " New Mexico", " New York", " North Carolina", " North Dakota", " Ohio", " Oklahoma", " Oregon", " Pennsylvania", " Rhode Island", " South Carolina", " South Dakota", " Tennessee", " Texas", " Utah", " Vermont", " Virginia", " Washington", " West Virginia", " Wisconsin", " Wyoming"}; if (value > states[]) { throw new ArgumentException(nameof(value), value, $"{nameof(states[])} That state doesn't exist"); } } } public Address(string street, string city, string state, string zip) { Street = street; City = city; // State = state; Zip = zip; }
public override string ToString() { string adr = $"{Street}, {City}, {State}, {Zip}"; return adr; } } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started