-
-
Save codecademydev/1c7afb6055fa789dd7b1bce197a2ba7e to your computer and use it in GitHub Desktop.
Codecademy export
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Define IDisplayable in this file | |
using System; | |
namespace SavingInterface | |
{ | |
interface IDisplayable | |
{ | |
void Display(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Define IResetable in this file | |
using System; | |
namespace SavingInterface | |
{ | |
interface IResetable | |
{ | |
void Reset(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace SavingInterface | |
{ | |
class PasswordManager: IDisplayable, IResetable | |
{ | |
private string Password | |
{ get; set; } | |
public bool Hidden | |
{ get; private set; } | |
public PasswordManager(string password, bool hidden) | |
{ | |
Password = password; | |
Hidden = hidden; | |
} | |
public void Display() | |
{ | |
Console.WriteLine("Password"); | |
Console.WriteLine("----------"); | |
Console.WriteLine(Hidden ? "***" : Password); | |
Console.WriteLine(String.Empty); | |
} | |
public void Reset() | |
{ | |
Password = String.Empty; | |
Hidden = false; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace SavingInterface | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
TodoList tdl = new TodoList(); | |
tdl.Add("Invite friends"); | |
tdl.Add("Buy decorations"); | |
tdl.Add("Party"); | |
tdl.Display(); | |
tdl.Reset(); | |
tdl.Display(); | |
PasswordManager pm = new PasswordManager("iluvpie", true); | |
pm.Display(); | |
pm.Reset(); | |
pm.Display(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace SavingInterface | |
{ | |
class TodoList: IDisplayable, IResetable | |
{ | |
public string[] Todos | |
{ get; private set; } | |
private int nextOpenIndex; | |
public TodoList() | |
{ | |
Todos = new string[5]; | |
nextOpenIndex = 0; | |
} | |
public void Add(string todo) | |
{ | |
Todos[nextOpenIndex] = todo; | |
nextOpenIndex++; | |
} | |
public void Display() | |
{ | |
Console.WriteLine("Todos"); | |
Console.WriteLine("----------"); | |
foreach (string todo in Todos) | |
{ | |
Console.WriteLine(todo != null ? todo : "[Add a todo~]"); | |
} | |
Console.WriteLine(String.Empty); | |
} | |
public void Reset() | |
{ | |
Todos = new string[5]; | |
nextOpenIndex = 0; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment