Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Lim Yu Long] ip #634

Open
wants to merge 51 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
d839859
Add Gradle support
May 24, 2020
eec5f1f
Level-1
yulonglim Aug 18, 2021
e5177f0
Level-1
yulonglim Aug 18, 2021
6328329
Level-2
yulonglim Aug 18, 2021
df8688b
Level-3
yulonglim Aug 18, 2021
c66222c
Level-4
yulonglim Aug 18, 2021
4e953c0
Level-4
yulonglim Aug 18, 2021
9e177ea
Level-6
yulonglim Aug 18, 2021
c6600c4
Added options to save file + more OOP
yulonglim Aug 25, 2021
ec68756
Second week work
yulonglim Aug 25, 2021
bc9975c
Merge pull request #1 from yulonglim/branch-Level-7
yulonglim Aug 25, 2021
b220aca
Added gradle support
yulonglim Aug 31, 2021
e9865c3
Merge pull request #2 from yulonglim/add-gradle-support
yulonglim Aug 31, 2021
1c62cc6
Added gui
yulonglim Aug 31, 2021
501bae5
Update build.gradle
yulonglim Aug 31, 2021
546cdf1
Merge branch 'master' into branch-Level-10
yulonglim Aug 31, 2021
30d2353
Merge pull request #3 from yulonglim/branch-Level-10
yulonglim Aug 31, 2021
1567d4d
Update Controller.java
yulonglim Aug 31, 2021
281f074
Updated readme
yulonglim Sep 1, 2021
65ecfad
Merge pull request #4 from yulonglim/Use-GFMD
yulonglim Sep 1, 2021
2f476f2
Update README.md
yulonglim Sep 1, 2021
503fa60
Update README.md
yulonglim Sep 2, 2021
1ad1526
Merge pull request #5 from yulonglim/Use-GFMD-1
yulonglim Sep 2, 2021
f46338a
Merge pull request #6 from yulonglim/Use-GFMD
yulonglim Sep 2, 2021
864e258
Current find is case sensitive
yulonglim Sep 5, 2021
ead486c
Merge pull request #8 from yulonglim/A-Assertions
yulonglim Sep 5, 2021
f08b6f3
Current Code is not of high quality
yulonglim Sep 7, 2021
08ca499
Merge pull request #9 from yulonglim/A-CodeQuality
yulonglim Sep 7, 2021
0340b8a
Current Code does not allow for updating of task
yulonglim Sep 7, 2021
1ba4022
Merge pull request #10 from yulonglim/C-update
yulonglim Sep 7, 2021
0c5c99b
Current Code does not allow for updating of task
yulonglim Sep 7, 2021
7e17e7f
Merge pull request #11 from yulonglim/C-update
yulonglim Sep 7, 2021
b5c99c3
Ui.png added
yulonglim Sep 14, 2021
6dd13f2
Added User Guide
yulonglim Sep 14, 2021
db716a6
Updated UserGuide
yulonglim Sep 14, 2021
3623e91
Improved code coverage for certain use case
yulonglim Sep 14, 2021
ea2de4a
Updated some method headers to reflect changes from 2103 bot
yulonglim Sep 14, 2021
3f00b07
Updated code to be able to build and run at java 11
yulonglim Sep 14, 2021
3121a7a
Current code requires users to press load at first run
yulonglim Sep 14, 2021
6634b2a
Merge pull request #13 from yulonglim/A-UserGuide
yulonglim Sep 14, 2021
121c99f
added inline text
yulonglim Sep 16, 2021
297c3e9
Merge pull request #14 from yulonglim/Use-GFMD
yulonglim Sep 16, 2021
ddae27e
Current code had a small bug due to previous update which caused some…
yulonglim Oct 2, 2021
38f6f32
Merge remote-tracking branch 'origin/master'
yulonglim Oct 2, 2021
23edda1
Update Controller.java
yulonglim Oct 2, 2021
770f309
DukeTest file was moved by accident during one of the updates and was…
yulonglim Oct 2, 2021
96f960a
Merge remote-tracking branch 'origin/master'
yulonglim Oct 2, 2021
a57ae3a
TaskList.java does not have javadocs
yulonglim Oct 11, 2021
3639cac
Storage load() method was too long and had parsing elements written in
yulonglim Oct 11, 2021
b022b4f
Cleaned up code
yulonglim Oct 11, 2021
c340be3
More abstraction done to make the code less nested given feedback fro…
yulonglim Oct 12, 2021
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
Prev Previous commit
Next Next commit
Added gui
yulonglim committed Aug 31, 2021
commit 1c62cc6dc71ead5b6b14daadd0a3faebfa6d346d
16 changes: 5 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
plugins {
id 'java'
id 'application'
id 'checkstyle'
id 'com.github.johnrengelman.shadow' version '5.1.0'
}

group 'org.example'
@@ -11,18 +9,14 @@ version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
sourceSets {
main {
java {
srcDirs = ['src']
}
}
}


dependencies {
implementation 'org.junit.jupiter:junit-jupiter:5.7.0'
compile 'junit:junit:4.12'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'

String javaFxVersion = '11'
String javaFxVersion = '16'

implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'win'
implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'mac'
147 changes: 147 additions & 0 deletions src/main/java/duke/Controller.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
package duke;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.DatePicker;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;

import java.io.IOException;
import java.util.ArrayList;


public class Controller {

private static Storage storage = new Storage("C:\\Users\\65906\\IdeaProjects\\ip\\duke.txt");
private static TaskList tasks;

@FXML
private Label listLabel;

@FXML
private Label deleteError;

@FXML
private TextField deleteText;

@FXML
private TextField taskType;

@FXML
private TextField taskDescription;

@FXML
private DatePicker taskDate;

@FXML
private Label addTaskError;

@FXML
private TextField doneText;

@FXML
private Label doneError;

@FXML
private TextField findText;

public void load(ActionEvent a) {
{
try {
tasks = new TaskList(storage.load());
} catch (IOException | DukeException e) {
tasks = new TaskList();
}
String listContent = "";
for (int i = 0; i < tasks.size(); i++) {
listContent += (i + 1) + ". " + tasks.getTask(i).toString() + "\n";
}
listLabel.setText("Here are the tasks in your list:\n" + listContent);
}
}

public void load() {
String listContent = "";
for (int i = 0; i < tasks.size(); i++) {
listContent += (i + 1) + ". " + tasks.getTask(i).toString() + "\n";
}
listLabel.setText("Here are the tasks in your list:\n" + listContent);
addTaskError.setText("");
deleteError.setText("");
doneError.setText("");
}

public Task taskParse(String type, String description, String dateTime){
if (type.equalsIgnoreCase("T")) {
return new Todo(description);
} else if (type.equalsIgnoreCase("D")) {
return new Deadline(description,dateTime);
} else if (type.equalsIgnoreCase("E")) {
return new Event(description,dateTime);
} else {
return null;
}
}

public void add(ActionEvent a) {
if (taskType.getText().equalsIgnoreCase("T")) {
tasks.addTask(taskParse(taskType.getText(), taskDescription.getText(), ""));
this.load();
} else if (taskType.getText().equalsIgnoreCase("D") || taskType.getText().equalsIgnoreCase( "E")) {
tasks.addTask(taskParse(taskType.getText(), taskDescription.getText(),
taskDate.getValue().toString()));
this.load();
} else {
addTaskError.setText("Wrong Format");
}

}

public void done(ActionEvent a) {
try {
int doneIndex = Integer.parseInt(doneText.getText()) - 1;
if(doneIndex > tasks.size() - 1 || doneIndex < 0) {
doneError.setText("Please enter a number in the list");
} else {
tasks.markAsDone(doneIndex);
this.load();
}
} catch (NumberFormatException e) {
doneError.setText("Please enter integer");
}
}

public void delete(ActionEvent a){
try {
int deleteIndex = Integer.parseInt(deleteText.getText()) - 1;
if(deleteIndex > tasks.size() - 1 || deleteIndex < 0) {
deleteError.setText("Please enter a number in the list");
} else {
tasks.removeTask(deleteIndex);

this.load();
}
} catch (NumberFormatException e) {
deleteError.setText("Please enter integer");
}
}

public void find(ActionEvent a) {
ArrayList<Task> result = new ArrayList<>();
String listContent = "";

for (int i = 0; i < tasks.size(); i++) {
if (tasks.getTask(i).description.contains(findText.getText())) {
result.add(tasks.getTask(i));
}
}
if (result.size() == 0) {
listLabel.setText("There are no matching task in your list!\nPress load to go back!");
} else {
for (int i = 0; i < result.size(); i++) {
listContent += (i + 1) + ". " + result.get(i).toString() + "\n";
}
listLabel.setText("Here are the matching tasks in your list:\n" + listContent + "Press load to go back!");
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These three methods seem to be very similar. See if you can reduce duplication.

}
2 changes: 1 addition & 1 deletion src/main/java/duke/Deadline.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main.java.duke;
package duke;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
84 changes: 42 additions & 42 deletions src/main/java/duke/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package main.java.duke;
package duke;

import java.io.IOException;
import java.util.Scanner;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.stage.Stage;

/**
@@ -13,48 +12,49 @@
* When run, parses input into parser class which utilizes ui class to give an output
* After each command it saves to the storage text file
*/
public class Duke {

private final Storage storage;
private final Ui ui;
private TaskList tasks;

public Duke(String filePath) {
ui = new Ui();
storage = new Storage(filePath);
try {
tasks = new TaskList(storage.load());
} catch (DukeException e) {
ui.showLoadingError();
tasks = new TaskList();
} catch (IOException e) {
e.printStackTrace();
}
}
public class Duke extends Application{

public static void main(String[] args) throws IOException {
new Duke("C:\\Users\\65906\\IdeaProjects\\ip\\duke.txt").run();
}

/**
* Starts the duke bot
*
* @throws IOException
*/
private void run() throws IOException {
ui.showWelcome();
Parser duke = new Parser(this.tasks);
Scanner sc = new Scanner(System.in);
while (sc.hasNextLine()) {
ui.showLine();
String str = sc.nextLine();
duke.parse(str);
ui.showLine();
storage.save(tasks);
}

public Duke() {}

}


// public static void startDuke() throws IOException {
// new Duke().run();
//
// }
//
// /**
// * Starts the duke bot
// *
// * @throws IOException
// */
// private void run() throws IOException {
// ui.showWelcome();
// Parser duke = new Parser(this.tasks);
// Scanner sc = new Scanner(System.in);
// while (sc.hasNextLine()) {
// ui.showLine();
// String str = sc.nextLine();
// duke.parse(str);
// ui.showLine();
// storage.save(tasks);
// }
//
//
// }



@Override
public void start(Stage stage) throws Exception {

Parent root = FXMLLoader.load(Duke.class.getResource("/duke.fxml"));
Scene scene = new Scene(root); // Setting the scene to be our Label

stage.setTitle("Duke Bot");
stage.setScene(scene); // Setting the stage to show our screen
stage.show(); // Render the stage.
}
}
2 changes: 1 addition & 1 deletion src/main/java/duke/DukeException.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main.java.duke;
package duke;

public class DukeException extends Exception {
private final String description;
2 changes: 1 addition & 1 deletion src/main/java/duke/DukeTest.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main.java.duke;
package duke;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
2 changes: 1 addition & 1 deletion src/main/java/duke/Event.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main.java.duke;
package duke;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
9 changes: 9 additions & 0 deletions src/main/java/duke/Launcher.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package duke;

import javafx.application.Application;

public class Launcher {
public static void main(String[] args) {
Application.launch(Duke.class, args);
}
}
5 changes: 4 additions & 1 deletion src/main/java/duke/Parser.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main.java.duke;
package duke;

/**
* Class which converts user command to functions
@@ -11,6 +11,7 @@ public Parser(TaskList taskList) {
this.taskList = taskList;
}


/**
* Takes in the user input and run functions that are associated with the input
*
@@ -57,4 +58,6 @@ public void parse(String input) {
}




}
2 changes: 1 addition & 1 deletion src/main/java/duke/Storage.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main.java.duke;
package duke;

import java.io.File;
import java.io.FileWriter;
2 changes: 1 addition & 1 deletion src/main/java/duke/Task.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main.java.duke;
package duke;

/**
* Task class used by the duke class
2 changes: 1 addition & 1 deletion src/main/java/duke/TaskList.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main.java.duke;
package duke;

import java.util.ArrayList;

2 changes: 1 addition & 1 deletion src/main/java/duke/Todo.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main.java.duke;
package duke;

/**
* class that extends task
2 changes: 1 addition & 1 deletion src/main/java/duke/Ui.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main.java.duke;
package duke;

/**
* Class which stores basic output of the bot
39 changes: 39 additions & 0 deletions src/main/resources/duke.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.Button?>
<?import javafx.scene.control.DatePicker?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.shape.Rectangle?>

<AnchorPane prefHeight="518.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/16" xmlns:fx="http://javafx.com/fxml/1" fx:controller="duke.Controller">
<children>
<Rectangle arcHeight="5.0" arcWidth="5.0" fill="#c8cacd" height="149.0" layoutX="2.0" layoutY="118.0" stroke="BLACK" strokeType="INSIDE" width="291.0" />
<Rectangle arcHeight="5.0" arcWidth="5.0" fill="#c8cacd" height="112.0" layoutX="2.0" layoutY="267.0" stroke="BLACK" strokeType="INSIDE" width="291.0" />
<Button layoutX="214.0" layoutY="298.0" mnemonicParsing="false" onAction="#delete" text="Delete" />
<Button layoutX="234.0" layoutY="209.0" mnemonicParsing="false" onAction="#add" text="Add" />
<Label fx:id="listLabel" alignment="TOP_CENTER" layoutX="293.0" layoutY="8.0" prefHeight="485.0" prefWidth="329.0" text="Press Load" />
<Button layoutX="300.0" layoutY="14.0" mnemonicParsing="false" onAction="#load" text="Load" />
<TextField fx:id="deleteText" layoutX="24.0" layoutY="295.0" />
<Label fx:id="deleteError" layoutX="23.0" layoutY="335.0" prefHeight="26.0" prefWidth="243.0" />
<TextField fx:id="taskType" layoutX="24.0" layoutY="148.0" />
<Label layoutX="24.0" layoutY="131.0" prefHeight="17.0" prefWidth="110.0" text="Add a Task" />
<Label layoutX="205.0" layoutY="152.0" prefHeight="17.0" prefWidth="85.0" text="Type (T,D,E)" />
<Label layoutX="203.0" layoutY="184.0" prefHeight="17.0" prefWidth="73.0" text="Description" />
<TextField fx:id="taskDescription" layoutX="24.0" layoutY="180.0" />
<DatePicker fx:id="taskDate" layoutX="23.0" layoutY="209.0" />
<Label layoutX="205.0" layoutY="213.0" prefHeight="17.0" prefWidth="42.0" text="Date" />
<Label fx:id="addTaskError" layoutX="23.0" layoutY="234.0" prefHeight="26.0" prefWidth="243.0" />
<Rectangle arcHeight="5.0" arcWidth="5.0" fill="#c8cacd" height="112.0" layoutX="2.0" layoutY="379.0" stroke="BLACK" strokeType="INSIDE" width="291.0" />
<Rectangle arcHeight="5.0" arcWidth="5.0" fill="#c8cacd" height="112.0" layoutX="2.0" layoutY="9.0" stroke="BLACK" strokeType="INSIDE" width="291.0" />
<Label layoutX="24.0" layoutY="278.0" prefHeight="17.0" prefWidth="110.0" text="Delete a Task" />
<Label layoutX="23.0" layoutY="18.0" prefHeight="17.0" prefWidth="162.0" text="Completed a Task" />
<Button layoutX="214.0" layoutY="53.0" mnemonicParsing="false" onAction="#done" text="Complete" />
<TextField fx:id="doneText" layoutX="24.0" layoutY="53.0" />
<Label fx:id="doneError" layoutX="24.0" layoutY="87.0" prefHeight="17.0" prefWidth="243.0" />
<Label layoutX="24.0" layoutY="388.0" prefHeight="17.0" prefWidth="149.0" text="Find a Task" />
<TextField fx:id="findText" layoutX="24.0" layoutY="410.0" />
<Button layoutX="214.0" layoutY="410.0" mnemonicParsing="false" onAction="#find" text="Find" />
</children>
</AnchorPane>