Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ConsoleUI
- {
- class Program
- {
- static void Main(string[] args)
- {
- StandardMessages.WelcomeMessage();
- Person user = PersonDataCapture.Capture();
- bool isUserValid = PersonValidator.Validate(user);
- if (isUserValid == false)
- {
- StandardMessages.EndApplication();
- return;
- }
- AccountGenerator.CreateAccount(user);
- StandardMessages.EndApplication();
- }
- }
- }
- using System;
- namespace ConsoleUI
- {
- class Person
- {
- public string FirstName { get; set; }
- public string LastName { get; set; }
- }
- }
- using System;
- namespace ConsoleUI
- {
- class StandardMessages
- {
- public static void WelcomeMessage()
- {
- Console.WriteLine("Welcome to my application!");
- }
- public static void EndApplication()
- {
- Console.ReadLine();
- }
- public static void DisplayValidationError(string fieldName)
- {
- Console.WriteLine($"You did not give us a valid {fieldName}!");
- }
- }
- }
- using System;
- namespace ConsoleUI
- {
- class PersonValidator
- {
- public static bool Validate(Person person)
- {
- // Checks to be sure the first and last names are valid
- if (string.IsNullOrWhiteSpace(person.FirstName))
- {
- StandardMessages.DisplayValidationError("first name");
- return false;
- }
- if (string.IsNullOrWhiteSpace(person.LastName))
- {
- StandardMessages.DisplayValidationError("last name");
- return false;
- }
- return true;
- }
- }
- }
- using System;
- namespace ConsoleUI
- {
- class PersonDataCapture
- {
- public static Person Capture()
- {
- // Ask for user data
- Person output = new Person();
- Console.Write("What is your first name: ");
- output.FirstName = Console.ReadLine();
- Console.Write("What is your last name: ");
- output.LastName = Console.ReadLine();
- return output;
- }
- }
- }
- using System;
- namespace ConsoleUI
- {
- class AccountGenerator
- {
- public static void CreateAccount(Person user)
- {
- // Create a username for the person
- Console.WriteLine($"Your username is { user.FirstName.Substring(0, 1) }{ user.LastName }");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement