Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application Development And Administration

Authors: Mannino Michael

5th Edition

0983332401, 978-0983332404

More Books

Students also viewed these Databases questions

Question

Explain how a defined contribution pension plan works.

Answered: 1 week ago

Question

Write down the circumstances in which you led.

Answered: 1 week ago

Question

Why is the System Build Process an iterative process?

Answered: 1 week ago