diff --git a/README.md b/src/README.md similarity index 100% rename from README.md rename to src/README.md diff --git a/src/task.dart b/src/task.dart new file mode 100644 index 0000000..9e99cff --- /dev/null +++ b/src/task.dart @@ -0,0 +1,116 @@ +import 'dart:io'; + +class Task { + int id; + String? title; + String? description; + bool isCompleted; + + Task(this.id, this.title, this.description, this.isCompleted); +} + +class TaskManager { + List tasks = []; + int id = 1; + + //Add tasks + void addTask(String? title, String? description, bool isCompleted) { + tasks.add(Task(id, title, description, + isCompleted)); //takes constructor/object as a input + + id++; + + print("Task successfully added."); + print("\n****************************************"); + } + + //Display tasks + void display() { + print("\n**************Display tasks***************"); + if (tasks.isNotEmpty) { + for (int i = 0; i < tasks.length; i++) { + Task task = tasks[i]; + print( + "Task ID: ${task.id}\nTask name: ${task.title}\nTask Description: ${task.description}\nTask completed: ${task.isCompleted}"); + print("\n*****************************************"); + } + } else { + print("No tasks present."); + print("\n*******************************************"); + } + } + + //Delete tasks + void delete(taskid) { + print("\n**************Delete Task**************"); + if (tasks.isNotEmpty) { + for (int i = 0; i < tasks.length; i++) { + Task task = tasks[i]; + if (task.id == taskid) { + tasks.removeAt(i); + print("Task Removed Successfully."); + print("\n***************************************"); + break; + } else if (i == tasks.length - 1) { + print("ID not present."); + print("\n***************************************"); + } + } + } else { + print("No Task to delete."); + print("\n***************************************"); + } + } + + //Update tasks + void update(taskid) { + print("*****************Update Task*****************\n"); + if (tasks.isNotEmpty) { + for (int i = 0; i < tasks.length; i++) { + Task task = tasks[i]; + if (task.id == taskid) { + print("What do you want to update:"); + print("1)Title\n2)Description\n3)Status"); + int? option = int.tryParse(stdin.readLineSync() ?? '0'); + if (option == 1) { + print("Please enter the new title: "); + String? t = stdin.readLineSync(); + task.title = t; + print("Title of task updated successfully."); + print("\n*********************************************"); + } else if (option == 2) { + print("Please enter the new description: "); + String? d = stdin.readLineSync(); + task.description = d; + print("Description of task updated successfully."); + print("\n*********************************************"); + } else if (option == 3) { + print("Please enter the new status: "); + String? c = stdin.readLineSync(); + if (c == 'True' || c == 'true' || c == 'T' || c == 't') { + task.isCompleted = true; + print("Status of task updated successfully."); + print("\n*********************************************"); + } else if (c == 'False' || c == 'false' || c == 'F' || c == 'f') { + task.isCompleted = false; + print("Status of task updated successfully."); + print("\n*********************************************"); + } else { + print("Please enter a correct status."); + print("\n*********************************************"); + } + } else { + print("Please enter a valid option to update."); + print("\n*********************************************"); + } + } else if (i == tasks.length - 1) { + print("ID not present."); + print("\n*********************************************"); + } + } + } else { + print("No Task to update"); + print("\n*********************************************"); + } + } +} diff --git a/src/task_list.dart b/src/task_list.dart new file mode 100644 index 0000000..03d7ba0 --- /dev/null +++ b/src/task_list.dart @@ -0,0 +1,58 @@ +import 'task.dart'; +import 'dart:io'; + +/*Implement a menu-driven interface that allows users to +add, view, update, and delete tasks using the Task class.*/ +void main() { + TaskManager manager = new TaskManager(); + do { + print("\n*********Welcome to Task Management System*********\n"); + stdout.write( + 'Please choose an option from the menu:\n1)Add Task\n2)View Task\n3)Delete Task\n4)Update Task\n0)To Exit\n'); + + int? option = int.tryParse(stdin.readLineSync() ?? '0'); + + if (option == 1) { + print("\n****************Add Task****************\n"); + stdout.write("Please enter Task name: "); + String? name = stdin.readLineSync(); + + stdout.write("Please enter Task description: "); + String? description = stdin.readLineSync(); + + stdout.write("Is the task completed? (True/False): "); + String? status = stdin.readLineSync(); + + if (status == 'True' || + status == 'true' || + status == 'T' || + status == 't') { + manager.addTask(name, description, true); + } else if (status == 'False' || + status == 'false' || + status == 'F' || + status == 'f') { + manager.addTask(name, description, false); + } else { + print("Please enter a valid status"); + print("\n****************************************"); + } + } else if (option == 2) { + manager.display(); + } else if (option == 3) { + print("\nPlease enter the ID of the task you wish to delete: "); + int? id = int.tryParse(stdin.readLineSync() ?? '0'); + manager.delete(id); + } else if (option == 4) { + print("\nPlease enter the ID of the task you want to update:"); + int? id = int.tryParse(stdin.readLineSync() ?? '0'); + if (id == null) { + print("\nPlease enter a number."); + } else { + manager.update(id); + } + } else { + exit(0); + } + } while (true); +} diff --git a/src/variables.dart b/src/variables.dart new file mode 100644 index 0000000..1da95ae --- /dev/null +++ b/src/variables.dart @@ -0,0 +1,39 @@ +//import 'task.dart'; +import 'dart:io'; + +void main() { + //declare and initialize variables + + int number = 50; + String name = "Talyia"; + bool isSmart = true; + List colors = ["Red", "Blue", "Pink", "Purple"]; + List> id_name = [ + {1: "Talyia"}, + {2: "Ryam"} + ]; + + print('Number: $number'); + print('Name: $name'); + print('Smart?: $isSmart'); + print('Color: $colors'); + print('Id with name: $id_name'); + +//Error Handling + + try { + int result = 10 ~/ 0; + print('Result: $result'); + } catch (e) { + print("An error occurred: $e"); + } + +//take input from user + stdout.write('Enter your name: '); + String? name2 = stdin.readLineSync(); + print('Hello $name2!'); +//take input from user as int + stdout.write('Enter your age: '); + int? age = int.tryParse(stdin.readLineSync()!) ?? 0; + print('Age: $age'); +}