Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
205 changes: 204 additions & 1 deletion todo/src/main/java/edu/mentorship/Main.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,210 @@
package edu.mentorship;
import edu.mentorship.helpClasses.DateValidation;
import edu.mentorship.helpClasses.Display;
import edu.mentorship.service.TaskServices;
import edu.mentorship.tasks.DeadLine;
import edu.mentorship.tasks.Recurring;
import edu.mentorship.tasks.Simple;
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
TaskServices taskServices = new TaskServices();
Scanner scanner = new Scanner(System.in);
int menuChoice,taskType,index;
boolean startDateAsk;
String title,description,startDate,endDate;
System.out.println(" TASK MANAGEMENT SYSTEM (0_0)");
while (true)
{
Display.menu();
System.out.print("Enter your choice:\t");menuChoice = scanner.nextInt();
if(menuChoice <= 7)
{
switch (menuChoice)
{
// Add Task
case 1:
System.out.println("**************************************************************************************************************");
System.out.println("Task types:");
Display.taskTypes();
taskType = scanner.nextInt();

switch (taskType)
{
//Simple
case 1 :
System.out.print("enter task's title :\t");
scanner.nextLine();
title = scanner.nextLine();
System.out.print("enter task's description :\t");
description = scanner.nextLine();
System.out.print("Do you want add startDate?\t");
startDateAsk = scanner.nextBoolean();
scanner.nextLine();
if(startDateAsk){
System.out.print("enter task's startDate :\t"); startDate = scanner.nextLine();
taskServices.add(new Simple(title,description,startDate));
}
else {
taskServices.add(new Simple(title,description));
}
System.out.println("\n*****************************************BACK TO MENU******************************************************\n");
break;
//Recurring
case 2 :
System.out.print("enter task's title :\t");
scanner.nextLine();
title = scanner.nextLine();
System.out.print("enter task's descriotion :\t"); description = scanner.nextLine();
System.out.print("Do you want add startDate?\t"); startDateAsk = scanner.nextBoolean();
scanner.nextLine();
if(startDateAsk){
System.out.print("enter task's startDate :\t"); startDate = scanner.nextLine();
System.out.print("enter task's endDate :\t"); endDate = scanner.nextLine();

taskServices.add(new Recurring(title,description,startDate,endDate));
}
else {
System.out.print("enter task's endDate :\t"); endDate = scanner.nextLine();
taskServices.add(new Recurring(title,description,endDate));
}
System.out.println("\n*****************************************BACK TO MENU******************************************************\n");
break;
//DeadLine
case 3:
System.out.print("enter task's title :\t");
scanner.nextLine();
title = scanner.nextLine();
System.out.print("enter task's descriotion :\t"); description = scanner.nextLine();
System.out.print("Do you want add startDate?\t"); startDateAsk = scanner.nextBoolean();
scanner.nextLine();
if(startDateAsk){
System.out.print("enter task's startDate :\t"); startDate = scanner.nextLine();
System.out.print("enter task's endDate :\t"); endDate = scanner.nextLine();

taskServices.add(new DeadLine(title,description,startDate,endDate));
}
else {
System.out.print("enter task's endDate :\t"); endDate = scanner.nextLine();
taskServices.add(new DeadLine(title,description,endDate));
}
System.out.println("\n*****************************************BACK TO MENU******************************************************\n");
break;
}
break;
// Update Task
case 2:
System.out.println("**************************************************************************************************************");
System.out.println("Task types:");
Display.taskTypes();
taskType = scanner.nextInt();
System.out.println("enter Task's Index:\t"); index = scanner.nextInt(); scanner.nextLine();
if (!DateValidation.indexValid(index, TaskServices.getTasks())) {
System.out.println("\n*****************************************BACK TO MENU******************************************************\n");
break;
}
switch (taskType)
{
//Simple
case 1 :
System.out.print("enter task's newTitle :\t");
title = scanner.nextLine();
System.out.print("enter task's newDescription :\t");
description = scanner.nextLine();
System.out.print("Do you want update startDate(true/false)?\t");
startDateAsk = scanner.nextBoolean();
scanner.nextLine();
if(startDateAsk){
System.out.print("enter task's newStartDate :\t"); startDate = scanner.nextLine();
taskServices.update(index,title,description,startDate," ");
}
else {
taskServices.update(index,title,description," "," ");
}
System.out.println("\n*****************************************BACK TO MENU******************************************************\n");
break;
//Recurring
case 2 :
System.out.print("enter task's newTitle :\t");
scanner.nextLine();
title = scanner.nextLine();
System.out.print("enter task's newDescription :\t");
description = scanner.nextLine();
System.out.print("Do you want update startDate(true/false)?\t");
startDateAsk = scanner.nextBoolean();
scanner.nextLine();
if(startDateAsk){
System.out.print("enter task's newStartDate :\t"); startDate = scanner.nextLine();
System.out.print("enter task's newEndDate :\t"); endDate = scanner.nextLine();

taskServices.update(index,title,description,startDate,endDate);
}
else {
System.out.print("enter task's newEndDate :\t"); endDate = scanner.nextLine();
taskServices.update(index,title,description," "," ");
}
System.out.println("\n*****************************************BACK TO MENU******************************************************\n");
break;
//DeadLine
case 3:
System.out.print("enter task's newTitle :\t");
scanner.nextLine();
title = scanner.nextLine();
System.out.print("enter task's newDescription :\t");
description = scanner.nextLine();
System.out.print("Do you want update startDate(true/false)?\t");
startDateAsk = scanner.nextBoolean();
scanner.nextLine();
if(startDateAsk){
System.out.print("enter task's newStartDate :\t"); startDate = scanner.nextLine();
System.out.print("enter task's newEndDate :\t"); endDate = scanner.nextLine();

taskServices.update(index,title,description,startDate,endDate);
}
else {
System.out.print("enter task's newEndDate :\t"); endDate = scanner.nextLine();
taskServices.update(index,title,description," "," ");
}
System.out.println("\n*****************************************BACK TO MENU******************************************************\n");
break;
}
break;
// Remove Task
case 3:
System.out.println("**************************************************************************************************************");
System.out.println("enter Task's Index:\t"); index = scanner.nextInt(); scanner.nextLine();
taskServices.delete(index);
System.out.println("\n*****************************************BACK TO MENU******************************************************\n");

break;
// SetComplete
case 4 :
System.out.println("**************************************************************************************************************");
System.out.println("enter Task's Index:\t"); index = scanner.nextInt(); scanner.nextLine();
taskServices.setComplete(index);
System.out.println("\n*****************************************BACK TO MENU******************************************************\n");

break;
// print List
case 5:
System.out.println("**************************************************************************************************************");
System.out.println("\nList:");
taskServices.print();
System.out.println("\n*****************************************BACK TO MENU******************************************************\n");
break;
// Report
case 6:
System.out.println("**************************************************************************************************************");
Display.report();
System.out.println("\n*****************************************BACK TO MENU******************************************************\n");
break;
case 7:
return;
}
}else
System.out.println("choice number must be from menu!!!");
}
}
}
}

51 changes: 51 additions & 0 deletions todo/src/main/java/edu/mentorship/helpClasses/Count.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package edu.mentorship.helpClasses;

import edu.mentorship.service.Task;

import java.util.ArrayList;
import java.util.Arrays;

public final class Count {

static int simple, recurring, deadLine;
static Object[][] commonList;

public static Object[][] mostCommon(ArrayList<Task> arr) {
// Reset counters to avoid accumulating values across multiple calls
simple = recurring = deadLine = 0;

// Count task types
for (Task task : arr) {
switch (task.getTaskType()) {
case "Simple" -> simple++;
case "Recurring" -> recurring++;
case "DeadLine" -> deadLine++;
}
}

// Update the array dynamically
commonList = new Object[][]{
{simple, "SimpleTask"},
{recurring, "RecurringTask"},
{deadLine, "DeadLineTask"}
};

// Sort by task count in descending order
Arrays.sort(commonList, (a, b) -> Integer.compare((int) b[0], (int) a[0]));

return commonList;
}

public static void printCommonList() {
// Check if commonList is initialized
if (commonList == null) {
System.out.println("Error: Call mostCommon() before printing!");
return;
}

// Print the sorted task types with counts
for (Object[] row : commonList) {
System.out.println(row[1] + " -> " + row[0]);
}
}
}
39 changes: 39 additions & 0 deletions todo/src/main/java/edu/mentorship/helpClasses/DateValidation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package edu.mentorship.helpClasses;

import edu.mentorship.service.Task;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.ArrayList;
public final class DateValidation {
static boolean valid = false;
static LocalDate date;
public static boolean isValid(String date) {
try {

DateValidation.date = LocalDate.parse(date, DateTimeFormatter.ofPattern("yyyy-MM-dd"));

if (!DateValidation.date.isBefore(LocalDate.now())) {
valid = true;
} else {
valid = false;
System.out.println("Date must be today or a future date.");
}
} catch (DateTimeParseException e) {
valid = false;
System.out.println("Please enter the correct format (yyyy-MM-dd).");
}
return valid;
}
public static boolean indexValid(int index , ArrayList<Task> arr) {
if(index < 0 || index >= arr.size() )
{
System.out.println("invalid index!");
return false;
}
else {
return true;
}
}
}
51 changes: 51 additions & 0 deletions todo/src/main/java/edu/mentorship/helpClasses/Display.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package edu.mentorship.helpClasses;

import edu.mentorship.service.TaskServices;

import static edu.mentorship.service.TaskServices.*;

public final class Display {
public static void menu(){
System.out.println("""
1.Add Task \

2.Update Task.\

3.Remove Task.\

4.Set Complete\

5.List all the Tasks\

6.Report\

7.Exit.""");
}
public static void taskTypes()
{
System.out.println("""
1.Simple \

2.Recurring \

3.DeadlLine \

""");
}
public static float productivityRatio()
{
if (getAllTasks() == 0)
return getCompleted();
return (float)getCompleted() / getAllTasks();
}
public static void report()
{
System.out.println("1.Count of completed tasks:\t" + getCompleted() );
System.out.println("2.Count of uncompleted tasks:\t"+ getNotCompleted());
System.out.println("3.Productivity ratio:\t" + productivityRatio());
Count.mostCommon(TaskServices.getTasks());
System.out.println("4.Top 3 Most Common Task Types.");
Count.printCommonList();

}
}
23 changes: 23 additions & 0 deletions todo/src/main/java/edu/mentorship/helpClasses/PrintTasks.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package edu.mentorship.helpClasses;

import edu.mentorship.service.Task;

import java.util.ArrayList;

import static edu.mentorship.helpClasses.Sort.sortTasks;
public final class PrintTasks {

public static void printTasks(ArrayList<Task> arr) {
if(arr.isEmpty())
{
System.out.println("List is empty!");
return;
}

sortTasks(arr);
for (Task task : arr) {
System.out.println(arr.indexOf(task)+". "+task.toString());
}

}
}
Loading