Page 1 of 1

C# required HI i need to move a task in its respective priority list by setting the place (priority). move a task from o

Posted: Sat May 14, 2022 3:15 pm
by answerhappygod
C# required
HI i need to
move a task in its respective priority list by setting the place
(priority).
move a task from one category to another.
highlight important tasks so that they appear in red in the
terminal.
Every task must be characterised by a due date printed along
with the name. This might need to enlarge the size of the table’s
columns.
im close but im stuck, thanks
Current Code C#
using System;
using System.Collections.Generic;
namespace DuplicateCode
{
class Category
{
public string Name { get; set; }
public List Tasks { get; set; }
public Category(string name)
{
Name = name;
Tasks = new List();
}
}
class Task
{
public string Name { get; set; }
public int Priority { get; set; }
public bool Highlighted { get; set; }
public string Due { get; set; }
public Task(string name, bool highlighted)
{
Name = name;
Highlighted = highlighted;
}
}
class DuplicateCode
{
static void InitCategories(List categories)
{
Console.WriteLine("Please enter three categories to begin with:
");
int i = 3;
while (i > 0)
{
Console.Write(">> ");
string categoryName = Console.ReadLine();
if (categoryName == "")
{
Console.WriteLine("Field cannot be left empty");
continue;
}
Category category = new Category(categoryName);
categories.Add(category);
i--;
}
}
static void DrawCategories(List categories)
{
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine(new string(' ', 12) + "CATEGORIES");
Console.WriteLine(new string(' ', 10) + new string('-',
94));
Console.Write("{0, 10}|", "item #");
foreach (var category in categories)
{
Console.Write("{0, 30}|", category.Name);
}
Console.WriteLine();
Console.WriteLine(new string(' ', 10) + new string('-',
94));
}
static int Choose()
{
Console.WriteLine("Enter your menu choice: ");
Console.WriteLine("1. Add a category");
Console.WriteLine("2. Delete an existing category");
Console.WriteLine("3. Add a task to a category");
Console.WriteLine("4. Delete an existing task");
Console.WriteLine("5. Change task priority");
Console.WriteLine("6. Move a task from one category to
another");
Console.WriteLine("7. Highlight a task");
Console.WriteLine("8. Quit");
int choice = Convert.ToInt32(Console.ReadLine());
return choice;
}
static void DeleteCategory(List categories)
{
Console.WriteLine("Which category would you like to
delete?");
string categoryToDelete = Console.ReadLine().ToLower();
foreach (var category in categories)
{
if (categoryToDelete == category.Name.ToLower())
{
categories.Remove(category);
break;
}
}
}
static void AddCategory(List categories)
{
if (categories.Count == 3)
{
Console.WriteLine("Sorry, there are already three
categories.");
Console.ReadLine();
return;
}
Console.WriteLine("Please enter the name of the category you
would like to add: ");
string categoryName = Console.ReadLine();
Category category = new Category(categoryName);
categories.Add(category);
}
static void AddTask(List categories)
{
Console.WriteLine("Please enter the name of the category you
would like to add the task to: ");
string categoryName = Console.ReadLine().ToLower();
Console.WriteLine("Please enter the name of the task you would
like to add: ");
string taskName = Console.ReadLine();
Task task = new Task(taskName, false);
foreach (var category in categories)
{
if (categoryName == category.Name.ToLower())
{
category.Tasks.Add(task);
break;
}
}
}
static void DeleteTask(List categories)
{
Console.WriteLine("Please enter the name of the category you
would like to delete the task from: ");
string categoryName = Console.ReadLine().ToLower();
Console.WriteLine("Please enter the name of the task you would
like to delete: ");
string taskName = Console.ReadLine().ToLower();
foreach (var category in categories)
{
if (categoryName == category.Name.ToLower())
{
foreach (var task in category.Tasks)
{
if (taskName == task.Name.ToLower())
{
category.Tasks.Remove(task);
return;
}
}
}
}
}
static void DrawTasks(List categories)
{
foreach (var category in categories)
{
if (category.Tasks.Count > 0)
{
foreach (var task in category.Tasks)
{
Console.Write("{0,30}|", task.Name);
}
}
else
{
Console.Write("{0,30}|", "N/A");
}
}
Console.WriteLine();
}
static void Main(string[] args)
{
string[] tasksIndividual = new string[0], tasksWork = new
string[0], tasksFamilly = new string[0];
List categories = new List();
InitCategories(categories);
while (true)
{
int choice = Choose();
switch (choice)
{
case 1:
AddCategory(categories);
break;
case 2:
DeleteCategory(categories);
break;
case 3:
AddTask(categories);
break;
case 4:
DeleteTask(categories);
break;
}
Console.Clear();
int max = tasksIndividual.Length > tasksWork.Length ?
tasksIndividual.Length : tasksWork.Length;
max = max > tasksFamilly.Length ? max :
tasksFamilly.Length;
DrawCategories(categories);
DrawTasks(categories);
}
}
}
}