Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created October 24, 2022 14:54
Show Gist options
  • Save codecademydev/1c7afb6055fa789dd7b1bce197a2ba7e to your computer and use it in GitHub Desktop.
Save codecademydev/1c7afb6055fa789dd7b1bce197a2ba7e to your computer and use it in GitHub Desktop.
Codecademy export
// Define IDisplayable in this file
using System;
namespace SavingInterface
{
interface IDisplayable
{
void Display();
}
}
// Define IResetable in this file
using System;
namespace SavingInterface
{
interface IResetable
{
void Reset();
}
}
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;
}
}
}
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();
}
}
}
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