├── TaskPriority.java ├── Priority.java ├── Status.java ├── TaskStatus.java ├── Label.java ├── Query.sql ├── Tag.java ├── Notes.java ├── User.java ├── Reminder.java ├── Contact.java ├── UserPreferences.java ├── Subtask.java ├── Feedback.java ├── Category.java ├── README.md ├── File.java ├── Location.java ├── UserData.java ├── TaskManager.java ├── FrontEnd.html ├── style.css ├── index.html ├── Task.java ├── RecommendationAlgorithm.java ├── TaskPredictor.java ├── MySqlConnection.java └── TaskRecommendationSystem.java /TaskPriority.java: -------------------------------------------------------------------------------- 1 | public enum TaskPriority { 2 | HIGH, MEDIUM, LOW 3 | } -------------------------------------------------------------------------------- /Priority.java: -------------------------------------------------------------------------------- 1 | public enum Priority { 2 | HIGH, 3 | MEDIUM, 4 | LOW 5 | } -------------------------------------------------------------------------------- /Status.java: -------------------------------------------------------------------------------- 1 | public enum Status { 2 | INCOMPLETE, 3 | COMPLETED 4 | } 5 | -------------------------------------------------------------------------------- /TaskStatus.java: -------------------------------------------------------------------------------- 1 | public enum TaskStatus { 2 | NEW, IN_PROGRESS, COMPLETED, CANCELLED 3 | } -------------------------------------------------------------------------------- /Label.java: -------------------------------------------------------------------------------- 1 | public class Label { 2 | private String name; 3 | 4 | public Label(String name) { 5 | this.name = name; 6 | } 7 | 8 | public String getName() { 9 | return name; 10 | } 11 | } -------------------------------------------------------------------------------- /Query.sql: -------------------------------------------------------------------------------- 1 | USE mysql2; 2 | 3 | CREATE TABLE tasks ( 4 | id INT NOT NULL AUTO_INCREMENT, 5 | name VARCHAR(255) NOT NULL, 6 | description VARCHAR(1000), 7 | status VARCHAR(20) NOT NULL, 8 | priority VARCHAR(20) NOT NULL, 9 | due_date DATE NOT NULL, 10 | PRIMARY KEY (id) 11 | ); 12 | -------------------------------------------------------------------------------- /Tag.java: -------------------------------------------------------------------------------- 1 | public class Tag { 2 | private String name; 3 | 4 | public Tag(String name) { 5 | this.name = name; 6 | } 7 | 8 | public String getName() { 9 | return name; 10 | } 11 | 12 | public void setName(String name) { 13 | this.name = name; 14 | } 15 | } -------------------------------------------------------------------------------- /Notes.java: -------------------------------------------------------------------------------- 1 | public class Notes { 2 | private String notes; 3 | 4 | public Notes(String notes) { 5 | this.notes = notes; 6 | } 7 | 8 | public String getNotes() { 9 | return notes; 10 | } 11 | 12 | public void setNotes(String notes) { 13 | this.notes = notes; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /User.java: -------------------------------------------------------------------------------- 1 | public class User { 2 | private String username; 3 | private String password; 4 | 5 | public User(String username, String password) { 6 | this.username = username; 7 | this.password = password; 8 | } 9 | 10 | public String getUsername() { 11 | return username; 12 | } 13 | 14 | public String getPassword() { 15 | return password; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Reminder.java: -------------------------------------------------------------------------------- 1 | import java.util.Date; 2 | 3 | public class Reminder { 4 | private Date date; 5 | private String message; 6 | 7 | public Reminder(Date date, String message) { 8 | this.date = date; 9 | this.message = message; 10 | } 11 | 12 | public Date getDate() { 13 | return date; 14 | } 15 | 16 | public String getMessage() { 17 | return message; 18 | } 19 | } -------------------------------------------------------------------------------- /Contact.java: -------------------------------------------------------------------------------- 1 | public class Contact { 2 | private String name; 3 | private String email; 4 | 5 | public Contact(String name, String email) { 6 | this.name = name; 7 | this.email = email; 8 | } 9 | 10 | public String getName() { 11 | return name; 12 | } 13 | 14 | public String getEmail() { 15 | return email; 16 | } 17 | 18 | public void setEmail(String email) { 19 | this.email = email; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /UserPreferences.java: -------------------------------------------------------------------------------- 1 | import java.util.HashMap; 2 | import java.util.Map; 3 | 4 | public class UserPreferences { 5 | private Map preferences; 6 | 7 | public UserPreferences() { 8 | preferences = new HashMap<>(); 9 | } 10 | 11 | public void setPreference(String key, Object value) { 12 | preferences.put(key, value); 13 | } 14 | 15 | public Object getPreference(String key) { 16 | return preferences.get(key); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Subtask.java: -------------------------------------------------------------------------------- 1 | public class Subtask { 2 | private String name; 3 | private boolean completed; 4 | 5 | public Subtask(String name) { 6 | this.name = name; 7 | this.completed = false; 8 | } 9 | 10 | public String getName() { 11 | return name; 12 | } 13 | 14 | public boolean isCompleted() { 15 | return completed; 16 | } 17 | 18 | public void setCompleted(boolean completed) { 19 | this.completed = completed; 20 | } 21 | } -------------------------------------------------------------------------------- /Feedback.java: -------------------------------------------------------------------------------- 1 | public class Feedback { 2 | 3 | private Task task; 4 | private int rating; 5 | private String comments; 6 | 7 | public Feedback(Task task, int rating, String comments) { 8 | this.task = task; 9 | this.rating = rating; 10 | this.comments = comments; 11 | } 12 | 13 | public Task getTask() { 14 | return task; 15 | } 16 | 17 | public int getRating() { 18 | return rating; 19 | } 20 | 21 | public String getComments() { 22 | return comments; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Category.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.List; 3 | 4 | public class Category { 5 | private String name; 6 | private List tasks; 7 | 8 | public Category(String name) { 9 | this.name = name; 10 | this.tasks = new ArrayList(); 11 | } 12 | 13 | public String getName() { 14 | return name; 15 | } 16 | 17 | public List getTasks() { 18 | return tasks; 19 | } 20 | 21 | public void addTask(Task task) { 22 | tasks.add(task); 23 | } 24 | 25 | public void removeTask(Task task) { 26 | tasks.remove(task); 27 | } 28 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AI-To-Do-List-Cooking-Recipe-Generator-App 2 | SQL, HTML, Java 3 | 4 | Using cutting-edge machine learning algorithms, this app not only tracks users' tasks and reminds them of upcoming deadlines, but also offers personalized recipe suggestions based on their dietary preferences, 5 | ingredients on hand, and cooking experience level. Say goodbye to boring meals and hello to culinary creativity! 6 | As the lead developer of this project, I worked closely with a team of designers and data scientists to bring this app to life. 7 | From ideation to implementation, we prioritized user experience and personalization to create an intuitive and enjoyable application that adapts to their unique needs. 8 | -------------------------------------------------------------------------------- /File.java: -------------------------------------------------------------------------------- 1 | public class File { 2 | private String name; 3 | private String type; 4 | private String path; 5 | 6 | public File(String name, String type, String path) { 7 | this.name = name; 8 | this.type = type; 9 | this.path = path; 10 | } 11 | 12 | public String getName() { 13 | return name; 14 | } 15 | 16 | public String getType() { 17 | return type; 18 | } 19 | 20 | public String getPath() { 21 | return path; 22 | } 23 | 24 | public void setName(String name) { 25 | this.name = name; 26 | } 27 | 28 | public void setType(String type) { 29 | this.type = type; 30 | } 31 | 32 | public void setPath(String path) { 33 | this.path = path; 34 | } 35 | } -------------------------------------------------------------------------------- /Location.java: -------------------------------------------------------------------------------- 1 | public class Location { 2 | private String name; 3 | private double latitude; 4 | private double longitude; 5 | 6 | public Location(String name, double latitude, double longitude) { 7 | this.name = name; 8 | this.latitude = latitude; 9 | this.longitude = longitude; 10 | } 11 | 12 | public String getName() { 13 | return name; 14 | } 15 | 16 | public double getLatitude() { 17 | return latitude; 18 | } 19 | 20 | public double getLongitude() { 21 | return longitude; 22 | } 23 | 24 | public void setLatitude(double latitude) { 25 | this.latitude = latitude; 26 | } 27 | 28 | public void setLongitude(double longitude) { 29 | this.longitude = longitude; 30 | } 31 | } -------------------------------------------------------------------------------- /UserData.java: -------------------------------------------------------------------------------- 1 | import java.time.LocalDateTime; 2 | import java.util.Scanner; 3 | 4 | public class UserData { 5 | private Task task; 6 | private LocalDateTime completionTime; 7 | private String notes; 8 | 9 | public UserData(Task task) { 10 | this.task = task; 11 | this.completionTime = LocalDateTime.now(); 12 | this.notes = ""; 13 | } 14 | 15 | public Task getTask() { 16 | return task; 17 | } 18 | 19 | public LocalDateTime getCompletionTime() { 20 | return completionTime; 21 | } 22 | 23 | public String getNotes() { 24 | return notes; 25 | } 26 | 27 | public void setNotes(String notes) { 28 | this.notes = notes; 29 | } 30 | 31 | public void gatherData() { 32 | Scanner scanner = new Scanner(System.in); 33 | 34 | System.out.println("Task completed: " + task.getName()); 35 | System.out.print("Notes (optional): "); 36 | String notes = scanner.nextLine(); 37 | setNotes(notes); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /TaskManager.java: -------------------------------------------------------------------------------- 1 | import java.time.LocalDateTime; 2 | import java.util.HashMap; 3 | import java.util.Map; 4 | import java.util.Scanner; 5 | 6 | public class TaskManager { 7 | private Map completionTimes; 8 | private Map notes; 9 | 10 | public TaskManager() { 11 | this.completionTimes = new HashMap<>(); 12 | this.notes = new HashMap<>(); 13 | } 14 | 15 | public void addTask(Task task) { 16 | completionTimes.put(task, null); 17 | notes.put(task, ""); 18 | } 19 | 20 | public void completeTask(Task task) { 21 | // Update the completion time for the task 22 | LocalDateTime completionTime = LocalDateTime.now(); 23 | completionTimes.put(task, completionTime); 24 | 25 | // Gather notes from the user 26 | Scanner scanner = new Scanner(System.in); 27 | System.out.print("Enter notes for the completed task (press enter to skip): "); 28 | String userNotes = scanner.nextLine(); 29 | notes.put(task, userNotes); 30 | } 31 | 32 | public LocalDateTime getCompletionTime(Task task) { 33 | return completionTimes.get(task); 34 | } 35 | 36 | public String getNotes(Task task) { 37 | return notes.get(task); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /FrontEnd.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Customized To-Do List App 7 | 8 | 9 | 10 | 11 |
12 |

Customized To-Do List App

13 |
14 |
15 | 25 |
26 |

Your To-Do List

27 |
    28 | 29 |
30 |
31 | 32 | 33 | 34 |
35 |
36 |
37 |
38 |

© 2023 Customized To-Do List App. All Rights Reserved.

39 |
40 | 41 | 42 | -------------------------------------------------------------------------------- /style.css: -------------------------------------------------------------------------------- 1 | /* Universal Styles */ 2 | body { 3 | margin: 0px; 4 | background-color: whitesmoke; 5 | font-family: 'Rock Salt', cursive; 6 | text-align: center; 7 | } 8 | 9 | .secondary-background { 10 | background-color: snow; 11 | } 12 | 13 | .tagline { 14 | font-family: 'Quicksand', sans-serif; 15 | color: lightslategrey; 16 | line-height: 125px; 17 | } 18 | 19 | /* Header */ 20 | h1 { 21 | margin: 0; 22 | background-color: steelblue; 23 | line-height: 100px; 24 | color: khaki; 25 | } 26 | 27 | h2 { 28 | margin: 10px; 29 | } 30 | 31 | /* App Container */ 32 | .container { 33 | border: 2px solid snow; 34 | display: flex; 35 | } 36 | 37 | /* To Do Section */ 38 | .week { 39 | flex-grow: 3; 40 | flex-direction: column; 41 | } 42 | 43 | .row { 44 | min-height: 200px; 45 | display: flex; 46 | flex-wrap: wrap; 47 | justify-content: space-around; 48 | align-items: center; 49 | } 50 | 51 | .square { 52 | width: 125px; 53 | height: 125px; 54 | padding: 10px; 55 | display: flex; 56 | justify-content: center; 57 | align-items: center; 58 | } 59 | 60 | .day.square { 61 | background-color: steelblue; 62 | border: 1px solid white; 63 | } 64 | 65 | .task.square { 66 | background-color: khaki; 67 | border: 1px solid white; 68 | } 69 | 70 | .task p { 71 | font-family: 'Quicksand', sans-serif; 72 | font-weight: 700; 73 | font-size: 12px; 74 | } 75 | 76 | /* Reminders */ 77 | .reminders { 78 | background-color: khaki; 79 | flex-grow: 2; 80 | } 81 | 82 | .reminders h3 { 83 | width: 100%; 84 | margin: 10px; 85 | color: black; 86 | line-height: 90px; 87 | font-size: 24px; 88 | } 89 | 90 | /* Footer */ 91 | footer { 92 | font-size: 24px; 93 | } -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | To Do App 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 17 | 18 | 19 |
20 | 21 | 22 |
23 |
24 |

MON

25 |
26 |

Insert some information about your week here :)

27 |
28 |
29 |
30 |
31 |
32 |

TUE

33 |
34 |
35 |
36 |
37 |
38 |

WED

39 |
40 |
41 |
42 |
43 |
44 |

THU

45 |
46 |
47 |
48 |
49 |
50 |

FRI

51 |
52 |
53 |
54 |
55 |
56 | 57 | 58 |
59 |

Reminders

60 |
61 |
62 | 63 | 64 |
65 | Copyright Son (David) Nguyen, 2023. 66 |
67 | 68 | 69 | -------------------------------------------------------------------------------- /Task.java: -------------------------------------------------------------------------------- 1 | import java.time.Duration; 2 | 3 | import java.time.LocalDate; 4 | import java.time.temporal.ChronoUnit; 5 | 6 | public class Task { 7 | private int id; 8 | private String name; 9 | private String description; 10 | private Status status; 11 | private Priority priority; 12 | private LocalDate dueDate; 13 | 14 | private Duration duration; 15 | private String notes; 16 | private LocalDate completedDate; 17 | 18 | private LocalDate lastCompletionDate; 19 | 20 | public Task(int id, String name, String description, Status status, Priority priority, LocalDate dueDate, Duration duration, String notes) { 21 | this.id = id; 22 | this.name = name; 23 | this.description = description; 24 | this.status = status; 25 | this.priority = priority; 26 | this.dueDate = dueDate; 27 | this.duration = duration; 28 | this.notes = notes; 29 | this.lastCompletionDate = null; 30 | } 31 | 32 | public LocalDate getCompletedDate() { 33 | return completedDate; 34 | } 35 | 36 | public void setCompletedDate(LocalDate completedDate) { 37 | this.completedDate = completedDate; 38 | } 39 | 40 | public int getId() { 41 | return id; 42 | } 43 | 44 | public String getName() { 45 | return name; 46 | } 47 | 48 | public Duration getDuration() { 49 | return duration; 50 | } 51 | 52 | public String getNotes() { 53 | return notes; 54 | } 55 | 56 | public String getDescription() { 57 | return description; 58 | } 59 | 60 | public Status getStatus() { 61 | return status; 62 | } 63 | 64 | public Priority getPriority() { 65 | return priority; 66 | } 67 | 68 | public LocalDate getDueDate() { 69 | return dueDate; 70 | } 71 | 72 | public int getDaysSinceLastCompletion() { 73 | if (lastCompletionDate == null) { 74 | return Integer.MAX_VALUE; 75 | } else { 76 | return (int) ChronoUnit.DAYS.between(lastCompletionDate, LocalDate.now()); 77 | } 78 | } 79 | 80 | public void setLastCompletionDate(LocalDate date) { 81 | this.lastCompletionDate = date; 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /RecommendationAlgorithm.java: -------------------------------------------------------------------------------- 1 | import java.io.Serializable; 2 | import java.time.LocalDate; 3 | import java.time.temporal.ChronoUnit; 4 | import java.util.List; 5 | import java.util.stream.Collectors; 6 | 7 | public class RecommendationAlgorithm implements Serializable { 8 | private List tasks; 9 | private UserPreferences userPreferences; 10 | 11 | public RecommendationAlgorithm(List tasks, UserPreferences userPreferences) { 12 | this.tasks = tasks; 13 | this.userPreferences = userPreferences; 14 | } 15 | 16 | public Task recommendTask() { 17 | List incompletedTasks = getIncompletedTasks(); 18 | 19 | // Sort incompleted tasks by priority and days since last completion 20 | incompletedTasks.sort((task1, task2) -> { 21 | double task1Priority = convertPriorityToValue(task1.getPriority()); 22 | double task2Priority = convertPriorityToValue(task2.getPriority()); 23 | int result = Double.compare(task2Priority, task1Priority); 24 | if (result == 0) { 25 | int daysSinceLastCompletion1 = getDaysSinceLastCompletion(task1); 26 | int daysSinceLastCompletion2 = getDaysSinceLastCompletion(task2); 27 | result = Integer.compare(daysSinceLastCompletion1, daysSinceLastCompletion2); 28 | } 29 | return result; 30 | }); 31 | 32 | // Return the first task in the sorted list 33 | return incompletedTasks.get(0); 34 | } 35 | 36 | private List getIncompletedTasks() { 37 | // Get all tasks that have not been completed yet 38 | return tasks.stream() 39 | .filter(task -> task.getStatus() != Status.COMPLETED) 40 | .collect(Collectors.toList()); 41 | } 42 | 43 | private int getDaysSinceLastCompletion(Task task) { 44 | LocalDate lastCompleted = task.getCompletedDate(); 45 | if (lastCompleted == null) { 46 | // The task has never been completed, so return a large number 47 | return Integer.MAX_VALUE; 48 | } else { 49 | // Calculate the number of days between today and the last completion date 50 | LocalDate today = LocalDate.now(); 51 | long days = ChronoUnit.DAYS.between(lastCompleted, today); 52 | return (int) days; 53 | } 54 | } 55 | 56 | private double convertPriorityToValue(Priority priority) { 57 | double value; 58 | switch (priority) { 59 | case HIGH: 60 | value = 1.0; 61 | break; 62 | case MEDIUM: 63 | value = 0.5; 64 | break; 65 | case LOW: 66 | default: 67 | value = 0.0; 68 | break; 69 | } 70 | return value; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /TaskPredictor.java: -------------------------------------------------------------------------------- 1 | import java.time.Duration; 2 | import weka.classifiers.Classifier; 3 | import weka.classifiers.bayes.NaiveBayes; 4 | import weka.core.Attribute; 5 | import weka.core.DenseInstance; 6 | import weka.core.Instance; 7 | import weka.core.Instances; 8 | 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | public class TaskPredictor { 13 | private List tasks; 14 | 15 | public TaskPredictor(List tasks) { 16 | this.tasks = tasks; 17 | } 18 | 19 | public void predictTaskCompletionTime(Task task) throws Exception { 20 | // Build the training dataset 21 | Instances dataset = buildDataset(); 22 | 23 | // Build the classifier 24 | Classifier classifier = new NaiveBayes(); 25 | classifier.buildClassifier(dataset); 26 | 27 | // Build the test instance 28 | Instance testInstance = buildTestInstance(task, dataset); 29 | 30 | // Make the prediction 31 | double prediction = classifier.classifyInstance(testInstance); 32 | 33 | // Display the prediction 34 | System.out.println("Predicted task completion time for " + task.getName() + ": " + prediction + " days"); 35 | } 36 | 37 | private Instances buildDataset() { 38 | // Define the attributes 39 | Attribute priority = new Attribute("priority"); 40 | Attribute duration = new Attribute("duration"); 41 | Attribute notes = new Attribute("notes"); 42 | List statusValues = new ArrayList<>(); 43 | statusValues.add("completed"); 44 | statusValues.add("incomplete"); 45 | Attribute status = new Attribute("status", statusValues); 46 | 47 | // Create the dataset 48 | ArrayList attributes = new ArrayList<>(); 49 | attributes.add(priority); 50 | attributes.add(duration); 51 | attributes.add(notes); 52 | attributes.add(status); 53 | Instances dataset = new Instances("TaskCompletionTimes", attributes, tasks.size()); 54 | 55 | // Add the task instances to the dataset 56 | for (Task task : tasks) { 57 | double priorityValue = convertPriorityToValue(task.getPriority()); 58 | double durationValue = convertDurationToValue(task.getDuration()); 59 | Instance instance = new DenseInstance(4); 60 | instance.setValue(priority, priorityValue); 61 | instance.setValue(duration, durationValue); 62 | instance.setValue(notes, task.getNotes()); 63 | instance.setValue(status, task.getStatus().toString()); 64 | dataset.add(instance); 65 | } 66 | 67 | // Set the class index to the status attribute 68 | dataset.setClassIndex(3); 69 | 70 | return dataset; 71 | } 72 | 73 | private Instance buildTestInstance(Task task, Instances dataset) { 74 | // Create a new instance with the same attributes as the dataset 75 | Instance testInstance = new DenseInstance(dataset.numAttributes()); 76 | testInstance.setDataset(dataset); 77 | 78 | // Set the attribute values for the test instance 79 | double priorityValue = convertPriorityToValue(task.getPriority()); 80 | double durationValue = convertDurationToValue(task.getDuration()); 81 | testInstance.setValue(0, priorityValue); 82 | testInstance.setValue(1, durationValue); 83 | testInstance.setValue(2, task.getNotes()); 84 | 85 | return testInstance; 86 | } 87 | 88 | private double convertPriorityToValue(Priority priority) { 89 | switch (priority) { 90 | case HIGH: 91 | return 3.0; 92 | case MEDIUM: 93 | return 2.0; 94 | case LOW: 95 | return 1.0; 96 | default: 97 | return 0.0; 98 | } 99 | } 100 | 101 | 102 | private double convertDurationToValue(Duration duration) { 103 | // Convert the duration to seconds 104 | long seconds = (long) duration.getSeconds(); 105 | 106 | // Convert seconds to a value between 0 and 1 107 | double value = (double) seconds / (30.0 * 24.0 * 60.0 * 60.0); 108 | 109 | return value; 110 | } 111 | 112 | } 113 | -------------------------------------------------------------------------------- /MySqlConnection.java: -------------------------------------------------------------------------------- 1 | import java.sql.*; 2 | import java.time.Duration; 3 | import java.time.LocalDate; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | 8 | public class MySqlConnection { 9 | private static final String URL = "jdbc:mysql://localhost:3306/mysql2?user=root&password=Hoangson09112004@"; 10 | private static final String USERNAME = "root"; 11 | private static final String PASSWORD = "Hoangson09112004@"; 12 | 13 | public static Connection getConnection() throws SQLException { 14 | return DriverManager.getConnection(URL, USERNAME, PASSWORD); 15 | } 16 | 17 | public static List getAllTasks() throws SQLException { 18 | List tasks = new ArrayList<>(); 19 | 20 | Connection connection = DriverManager.getConnection(URL, USERNAME, PASSWORD); 21 | 22 | String query = "SELECT * FROM tasks"; 23 | 24 | try (PreparedStatement statement = connection.prepareStatement(query)) { 25 | ResultSet resultSet = statement.executeQuery(); 26 | 27 | while (resultSet.next()) { 28 | int id = resultSet.getInt("id"); 29 | String name = resultSet.getString("name"); 30 | String description = resultSet.getString("description"); 31 | Status status = Status.valueOf(resultSet.getString("status")); 32 | Priority priority = Priority.valueOf(resultSet.getString("priority")); 33 | LocalDate dueDate = resultSet.getDate("due_date").toLocalDate(); 34 | Duration duration = Duration.ofMinutes(resultSet.getLong("duration")); 35 | String notes = resultSet.getString("notes"); 36 | 37 | Task task = new Task(id, name, description, status, priority, dueDate, duration, notes); 38 | tasks.add(task); 39 | } 40 | } catch (SQLException e) { 41 | System.out.println("Error: " + e.getMessage()); 42 | } 43 | 44 | connection.close(); 45 | 46 | return tasks; 47 | } 48 | 49 | 50 | public static void addTask(Task task) throws SQLException { 51 | Connection connection = getConnection(); 52 | 53 | String query = "INSERT INTO tasks (name, description, status, priority, due_date) " + 54 | "VALUES (?, ?, ?, ?, ?)"; 55 | PreparedStatement statement = connection.prepareStatement(query); 56 | statement.setString(1, task.getName()); 57 | statement.setString(2, task.getDescription()); 58 | statement.setString(3, task.getStatus().toString()); 59 | statement.setString(4, task.getPriority().toString()); 60 | statement.setDate(5, Date.valueOf(task.getDueDate())); 61 | 62 | statement.executeUpdate(); 63 | 64 | closeConnection(connection, statement); 65 | } 66 | 67 | public static void updateTask(Task task) throws SQLException { 68 | Connection connection = getConnection(); 69 | 70 | String query = "UPDATE tasks SET name = ?, description = ?, status = ?, priority = ?, due_date = ? " + 71 | "WHERE id = ?"; 72 | PreparedStatement statement = connection.prepareStatement(query); 73 | statement.setString(1, task.getName()); 74 | statement.setString(2, task.getDescription()); 75 | statement.setString(3, task.getStatus().toString()); 76 | statement.setString(4, task.getPriority().toString()); 77 | statement.setDate(5, Date.valueOf(task.getDueDate())); 78 | statement.setInt(6, task.getId()); 79 | 80 | statement.executeUpdate(); 81 | 82 | closeConnection(connection, statement); 83 | } 84 | 85 | 86 | public static void deleteTask(int taskId) throws SQLException { 87 | try (Connection conn = getConnection(); 88 | PreparedStatement stmt = conn.prepareStatement("DELETE FROM tasks WHERE id=?")) { 89 | stmt.setInt(1, taskId); 90 | stmt.executeUpdate(); 91 | } 92 | } 93 | 94 | private static void closeConnection(Connection connection, PreparedStatement statement) throws SQLException { 95 | if (statement != null) { 96 | statement.close(); 97 | } 98 | if (connection != null) { 99 | connection.close(); 100 | } 101 | } 102 | 103 | } 104 | -------------------------------------------------------------------------------- /TaskRecommendationSystem.java: -------------------------------------------------------------------------------- 1 | import java.io.FileOutputStream; 2 | import java.io.IOException; 3 | import java.io.ObjectOutputStream; 4 | import java.time.LocalDate; 5 | import java.time.temporal.ChronoUnit; 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | import java.util.Map; 9 | import java.util.Scanner; 10 | import java.util.stream.Collectors; 11 | 12 | import java.time.Duration; 13 | import weka.classifiers.trees.J48; 14 | import weka.core.Attribute; 15 | import weka.core.DenseInstance; 16 | import weka.core.Instance; 17 | import weka.core.Instances; 18 | 19 | public class TaskRecommendationSystem { 20 | private List tasks; 21 | private Map taskNameToIdMap; 22 | 23 | private UserPreferences userPreferences; 24 | 25 | public TaskRecommendationSystem(List tasks) { 26 | this.tasks = tasks; 27 | this.taskNameToIdMap = tasks.stream().collect(Collectors.toMap(Task::getName, Task::getId)); 28 | this.userPreferences = new UserPreferences(); 29 | } 30 | 31 | public List recommendTasks(Task currentTask) throws Exception { 32 | // Build the training dataset 33 | Instances dataset = buildDataset(); 34 | 35 | // Build the classifier 36 | J48 classifier = new J48(); 37 | classifier.setUnpruned(true); 38 | classifier.buildClassifier(dataset); 39 | 40 | // Build the test instance 41 | Instance testInstance = buildTestInstance(currentTask, dataset); 42 | 43 | // Get the predicted class value 44 | double predictedClass = classifier.classifyInstance(testInstance); 45 | 46 | // Get the recommended task names 47 | List recommendedTaskNames = getRecommendedTaskNames(predictedClass); 48 | 49 | // Map the task names to task objects 50 | return recommendedTaskNames.stream().map(name -> tasks.get(taskNameToIdMap.get(name))).collect(Collectors.toList()); 51 | } 52 | 53 | private Instances buildDataset() { 54 | // Define the attributes 55 | Attribute priority = new Attribute("priority"); 56 | Attribute duration = new Attribute("duration"); 57 | Attribute notes = new Attribute("notes"); 58 | Attribute daysSinceLastCompletion = new Attribute("days_since_last_completion"); 59 | List statusValues = new ArrayList<>(); 60 | statusValues.add("completed"); 61 | statusValues.add("incomplete"); 62 | Attribute status = new Attribute("status", statusValues); 63 | 64 | // Create the dataset 65 | ArrayList attributes = new ArrayList<>(); 66 | attributes.add(priority); 67 | attributes.add(duration); 68 | attributes.add(notes); 69 | attributes.add(daysSinceLastCompletion); 70 | attributes.add(status); 71 | Instances dataset = new Instances("TaskRecommendations", attributes, tasks.size()); 72 | 73 | // Add the task instances to the dataset 74 | for (Task task : tasks) { 75 | double priorityValue = convertPriorityToValue(task.getPriority()); 76 | double durationValue = convertDurationToValue(task.getDuration()); 77 | double daysSinceLastCompletionValue = convertDaysSinceLastCompletionToValue(task.getDaysSinceLastCompletion()); 78 | Instance instance = new DenseInstance(5); 79 | instance.setValue(priority, priorityValue); 80 | instance.setValue(duration, durationValue); 81 | instance.setValue(notes, task.getNotes()); 82 | instance.setValue(daysSinceLastCompletion, daysSinceLastCompletionValue); 83 | instance.setValue(status, task.getStatus().toString()); 84 | dataset.add(instance); 85 | } 86 | 87 | // Set the class index to the status attribute 88 | dataset.setClassIndex(4); 89 | 90 | return dataset; 91 | } 92 | 93 | 94 | private Instance buildTestInstance(Task currentTask, Instances dataset) { 95 | Instance testInstance = new DenseInstance(5); 96 | double priorityValue = convertPriorityToValue(currentTask.getPriority()); 97 | double durationValue = convertDurationToValue(currentTask.getDuration()); 98 | double daysSinceLastCompletionValue = convertDaysSinceLastCompletionToValue(currentTask.getDaysSinceLastCompletion()); 99 | testInstance.setValue(dataset.attribute(0), priorityValue); 100 | testInstance.setValue(dataset.attribute(1), durationValue); 101 | testInstance.setValue(dataset.attribute(2), currentTask.getNotes()); 102 | testInstance.setValue(dataset.attribute(3), daysSinceLastCompletionValue); 103 | testInstance.setDataset(dataset); 104 | return testInstance; 105 | } 106 | 107 | 108 | private List getRecommendedTaskNames(double predictedClass) { 109 | List recommendedTaskNames = new ArrayList<>(); 110 | 111 | Task recommendedTask = null; 112 | // If the predicted class is "completed", recommend the highest-priority incomplete task 113 | if (predictedClass == 0) { 114 | List incompleteTasks = tasks.stream() 115 | .filter(task -> task.getStatus().equals(Status.INCOMPLETE)) 116 | .sorted((t1, t2) -> t2.getPriority().compareTo(t1.getPriority())) 117 | .collect(Collectors.toList()); 118 | if (!incompleteTasks.isEmpty()) { 119 | recommendedTaskNames.add(incompleteTasks.get(0).getName()); 120 | } 121 | } 122 | 123 | // If the predicted class is "incomplete", recommend the highest-priority task 124 | if (predictedClass == 1) { 125 | List sortedTasks = tasks.stream() 126 | .sorted((t1, t2) -> t2.getPriority().compareTo(t1.getPriority())) 127 | .collect(Collectors.toList()); 128 | if (!sortedTasks.isEmpty()) { 129 | recommendedTaskNames.add(sortedTasks.get(0).getName()); 130 | } 131 | } 132 | 133 | Feedback feedback = getUserFeedback(recommendedTask); 134 | adjustRecommendationAlgorithm(feedback); 135 | return recommendedTaskNames; 136 | } 137 | 138 | private Feedback getUserFeedback(Task recommendedTask) { 139 | Scanner scanner = new Scanner(System.in); 140 | System.out.println("The recommended task is: " + recommendedTask.getName()); 141 | System.out.println("How would you rate this task? (1-10)"); 142 | int rating = scanner.nextInt(); 143 | System.out.println("Would you like to add any comments? (y/n)"); 144 | String comments = ""; 145 | if (scanner.next().equalsIgnoreCase("y")) { 146 | System.out.println("Please enter your comments:"); 147 | comments = scanner.next(); 148 | } 149 | Feedback feedback = new Feedback(recommendedTask, rating, comments); 150 | saveFeedback(feedback); 151 | return feedback; 152 | } 153 | 154 | private double calculateScore(Task task) { 155 | double score = 0; 156 | double priorityValue = convertPriorityToValue(task.getPriority()); 157 | double durationValue = convertDurationToValue(task.getDuration()); 158 | double daysSinceCompletion = getDaysSinceLastCompletion(task); 159 | 160 | score += priorityValue; 161 | score += durationValue; 162 | score += daysSinceCompletion; 163 | 164 | return score; 165 | } 166 | 167 | private void adjustRecommendationAlgorithm(Feedback feedback) { 168 | // You can use the feedback to adjust the recommendation algorithm 169 | // For example, you could increase the score of tasks with similar characteristics to the recommended task 170 | // Or you could decrease the score of tasks with characteristics that the user did not like about the recommended task 171 | 172 | // For now, let's just print the feedback to the console 173 | System.out.println("User feedback:"); 174 | System.out.println("Task name: " + feedback.getTask().getName()); 175 | System.out.println("Rating: " + feedback.getRating()); 176 | System.out.println("Comments: " + feedback.getComments()); 177 | } 178 | 179 | private void saveFeedback(Feedback feedback) { 180 | System.out.println("Saving feedback:"); 181 | System.out.println("Task name: " + feedback.getTask().getName()); 182 | System.out.println("Rating: " + feedback.getRating()); 183 | System.out.println("Comments: " + feedback.getComments()); 184 | } 185 | 186 | public int getDaysSinceLastCompletion(Task task) { 187 | LocalDate lastCompleted = task.getCompletedDate(); 188 | if (lastCompleted == null) { 189 | // The task has never been completed, so return a large number 190 | return Integer.MAX_VALUE; 191 | } else { 192 | // Calculate the number of days between today and the last completion date 193 | LocalDate today = LocalDate.now(); 194 | long days = ChronoUnit.DAYS.between(lastCompleted, today); 195 | return (int) days; 196 | } 197 | } 198 | 199 | public void saveRecommendationAlgorithm(RecommendationAlgorithm algorithm) { 200 | // Save the algorithm to a file 201 | try (ObjectOutputStream outputStream = new ObjectOutputStream(new FileOutputStream("algorithm.ser"))) { 202 | outputStream.writeObject(algorithm); 203 | System.out.println("Algorithm saved successfully"); 204 | } catch (IOException e) { 205 | System.err.println("Error saving algorithm: " + e.getMessage()); 206 | } 207 | } 208 | 209 | private double convertPriorityToValue(Priority priority) { 210 | switch (priority) { 211 | case HIGH: 212 | return 1.0; 213 | case MEDIUM: 214 | return 0.5; 215 | case LOW: 216 | return 0.0; 217 | default: 218 | return 0.0; 219 | } 220 | } 221 | 222 | private double convertDurationToValue(Duration duration) { 223 | long seconds = duration.getSeconds(); 224 | return (double) seconds / (60 * 60); // Convert to hours 225 | } 226 | 227 | 228 | private double convertDaysSinceLastCompletionToValue(int daysSinceLastCompletion) { 229 | return (double) daysSinceLastCompletion / 30.0; 230 | } 231 | } 232 | --------------------------------------------------------------------------------