Visual Studio C# Name Formatter Create an application that lets the user enter t
ID: 669600 • Letter: V
Question
Visual Studio C#
Name Formatter
Create an application that lets the user enter the following pieces of data:
• The user’s first name
• The user’s middle name
• The user’s last name
• The user’s preferred title (Mr., Mrs., Ms., Dr., etc.)
Assume the user has entered the following data:
• First name: Kelly
• Middle name: Jane
• Last name: Smith
• Title: Ms.
The application should have buttons that display the user’s name formatted in the following ways:
Ms. Kelly Jane Smith
Kelly Jane Smith
Kelly Smith
Smith, Kelly Jane, Ms.
Smith, Kelly Jane
Smith, Kelly
Explanation / Answer
To create an application, the easiest way is defined below :
Step 1: Open the visual studio c#.
Step 2 : Use various buttons,box,... to create the application for user's full name.
Step 3 : After making the application, code will be automatically generated.
CODE : // Code for application created
namespace personApp
{
public class Person
{
public Person()
{
}
private Person(string firstName, string middleName, string lastName)
{
FirstName = firstName;
MiddleName = middleName;
LastName = lastName;
}
public string FirstName { get; }
public string MiddleName { get; }
public string LastName { get; }
public Person firstName(string firstName)
{
return new Person(firstName, LastName);
}
{
return new Person(MiddleName, LastName);
}
public Person lastName(string lastName)
{
return new Person(firstName, LastName);
}
public override string ToString()
{
return $ "{FirstName} {MiddleName} {LastName}";
}
}
}
private Person(string firstName, string middleName, string lastName)
{
FirstName = firstName;
MiddleName = middleName;
LastName = lastName;
}
public string FirstName { get; }
public string MiddleName { get; }
public string LastName { get; }
public Person firstName(string firstName)
{
return new Person(firstName, LastName);
}
public Person MiddleName(string MiddleName){
return new Person(MiddleName, LastName);
}
public Person lastName(string lastName)
{
return new Person(firstName, LastName);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.