You work as the Enterprise application developer at Domain.com. The Domain.com network consists of a single Active Directory domain named Domain.com. All servers in the domain run Windows Server 2003. Your responsibilities at Domain.com include the design and development of applications. Domain.com operates as a Geographic Positioning System service provider. You are currently developing a geographical mapping application. You must create a struct named Waypoint that models a waypoint. This waypoint is to consist of a set of latitude and longitude coordinates. In the event of a user passing a street address to the struct, it must perform a location lookup and set its coordinates appropriately.
To this end you need to define the Waypoint struct. You need to ensure that your application requires the least amount of code to set the coordinates from a street address.
What should you do? (Choose the correct code segment.)
A.
public struct Waypoint
{
public double Latitude;
public double Longitude;
public Waypoint FromAddress(String address)
{
Waypoint waypoint = new Waypoint();
// Set the Latitude and Longitude fields based on the address.
return waypoint
}
}
B.
public struct Waypoint
{
public double Latitude;
public double Longitude;
public Waypoint(String address)
{
//Set the Latitude and Longitude fields based on the address.
}
}
C.
public struct Waypoint
{
public double Latitude;
public double Longitude;
public String address
{
set
{
//Set the Latitude and Longitude fields based on the address.
}
}
}
D.
public struct Waypoint
{
public double Lattitude;
public double Longitude;
public void SetAddress(String address)
{
//Set the Latitude and Longitude fields based on the address.
}
}
Explanation:
When the Waypoint struct is defined with a non-default constructor, it allows calling code to initialize the Latitude and Longitude fields of the Waypoint struct when it is instantiated. This solution only uses one code statement.
Incorrect answers:
A: You should not add a non-static method to return a Waypoint instance. As such it would require applications to first initialize the Waypoint struct by calling its constructor and only then can applications call methods on the structs. Furthermore this solution will require two code statements.
C: You should not add a non-static method to set the Latitude and Longitude fields of the Waypoint instance. This will require the application to first initialize the Waypoint struct by calling its constructor and only then will the application be able to call methods on the struct. Besides this solution will require two code statements.
D: You should not add a property to set the Longitude and Latitude fields of the Waypoint instance. This will require the application to first initialize the Waypoint struct by calling its constructor and only then will the application be able to call methods on the struct. Besides this solution will require two code statements.