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

[Ria Khaitan] iP #328

Open
wants to merge 39 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
d839859
Add Gradle support
May 24, 2020
151461d
add level 1
riakhaitan Jan 28, 2022
47b8641
update gitignore
riakhaitan Jan 28, 2022
b17138e
Add, List
riakhaitan Jan 30, 2022
9c7b04f
mark as done
riakhaitan Jan 30, 2022
753720c
todos, events, deadlines
riakhaitan Feb 3, 2022
9b13c8d
add UI testing
riakhaitan Feb 4, 2022
83929b9
handle errors
riakhaitan Feb 4, 2022
23ce597
add delete
riakhaitan Feb 4, 2022
6ed0f74
add level 7 to branch-level-7
riakhaitan Feb 6, 2022
641333d
dates and times
riakhaitan Feb 6, 2022
04c29b8
fix merge conflicts{
riakhaitan Feb 6, 2022
b1955ad
more OOP
riakhaitan Feb 6, 2022
e290e05
java doc
riakhaitan Feb 8, 2022
08f9af6
packages
riakhaitan Feb 8, 2022
0d9e8c2
coding standard
riakhaitan Feb 8, 2022
7e9f3b7
find
riakhaitan Feb 8, 2022
7752dbf
add junit tests
riakhaitan Feb 10, 2022
2b8b28d
create a JAR file
riakhaitan Feb 10, 2022
ce15d66
add gradle support
riakhaitan Feb 10, 2022
73df732
add gradle support
riakhaitan Feb 10, 2022
5cec4bd
java doc
riakhaitan Feb 13, 2022
9a52a54
coding standard
riakhaitan Feb 13, 2022
e6d592a
fix find
riakhaitan Feb 13, 2022
e4b8c5a
fix coding standard
riakhaitan Feb 13, 2022
2bda280
merge find
riakhaitan Feb 13, 2022
f0b93f4
use assertions
riakhaitan Feb 13, 2022
34a78ab
code quality
riakhaitan Feb 13, 2022
a18e31b
Merge pull request #2 from riakhaitan/branch-A-Assertions
riakhaitan Feb 13, 2022
1640332
Merge pull request #3 from riakhaitan/branch-A-CodeQuality
riakhaitan Feb 13, 2022
8d134fe
Set theme jekyll-theme-cayman
riakhaitan Feb 21, 2022
2b126c7
Update ReadMe
riakhaitan Feb 21, 2022
48d87fc
build.gradle : Update dependancies in the file to add JavaFX dependen…
riakhaitan Feb 21, 2022
9bae6a7
add bcd extension
riakhaitan Feb 21, 2022
0583ae0
fix code for event
riakhaitan Feb 21, 2022
8281bb2
Update README.md
riakhaitan Feb 21, 2022
b3ed67a
add javafx
riakhaitan Feb 25, 2022
31e1a12
Merge branch 'master' of https://github.com/riakhaitan/ip
riakhaitan Feb 25, 2022
d97ad83
add ui.png
riakhaitan Feb 25, 2022
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ bin/

/text-ui-test/ACTUAL.txt
text-ui-test/EXPECTED-UNIX.TXT
*.class
Binary file added src/main/java/Duke.class
Binary file not shown.
213 changes: 206 additions & 7 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,209 @@
import exceptions.DukeExceptions;

Choose a reason for hiding this comment

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

Should the import statements be ordered differently?

import exceptions.DukeInvalidInput;
import exceptions.DukeInvalidTodo;

import java.io.*;
import java.util.Objects;
import java.time.LocalDate;
import java.util.Scanner;
import java.util.ArrayList;

public class Duke {
public static void main(String[] args) {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
public static void lineOne() {
System.out.println("*************************************************************************");
}

public static void lineTwo() {
System.out.println("|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|");
}

public static String makeDesc(String[] text, int len) {

Choose a reason for hiding this comment

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

Perhaps a more intuitive variable name here?

String newText = "";
for (int i = 1; i < len; i++) {
newText = newText + text[i] + " ";
}
return newText.trim();
}

public static void writeToFile(ArrayList<Task> list) throws IOException {
try {
File f = new File("/Users/riakhaitan/iP/ip/data/duke.txt");
f.createNewFile();

boolean directory = f.getParentFile().mkdirs();
Copy link

Choose a reason for hiding this comment

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

Just a suggestion, perhaps you could use a name for this variable that is more boolean-sounding such as isDirectory? Good use of mkdir() here, creating a directory to store data

FileWriter writer = new FileWriter(f, false);
for (Task task : list) {
String fileInput;
Task ele = task;
if (ele instanceof ToDo) {
fileInput = "[T][" + ele.getStatusIcon() + "]/" + ele.description;
} else if (ele instanceof Deadline) {
Deadline deadL = (Deadline) ele;
fileInput = "[D][" + deadL.getStatusIcon() + "]/" + deadL.description + "/" + deadL.when;
} else {
Event eve = (Event) ele;
fileInput = "[E][" + eve.getStatusIcon() + "]/" + eve.description + "/" + eve.at;
}
writer.write(fileInput + "\n");
writer.flush();
}
} catch (IOException ex) {
ex.printStackTrace();
}
}

public static void loadFromFile(ArrayList<Task> list) throws IOException {
File f = new File("/Users/riakhaitan/iP/ip/data/duke.txt");
f.createNewFile();
String input, desc;
Task t;
Scanner in = new Scanner(f);
while(in.hasNextLine()) {
input = in.nextLine();
String[] tSplit = input.split("/");
String[] splitT = tSplit[0].split("]");
switch(splitT[0]) {
case "[T":
t = new ToDo(tSplit[1]);
break;
case "[E":
t = new Event(tSplit[1], tSplit[2]);
break;
case "[D":
t = new Deadline(tSplit[1], LocalDate.parse(tSplit[2]));
break;
default:
t = new Task("eee");
break;
}
if(splitT[1].equals("[X")) {
t.done();
list.add(t);
}
else {
list.add(t);
}
}
printList(list, list.size());
in.close();
}

public static int exitHalloumi() {
lineOne();
System.out.println("See you soon! Have a good day ^_^");
lineOne();
return 1;
}

public static void printList(ArrayList<Task> list, int size) {
lineOne();
System.out.println("List:");
if(list.isEmpty()) {
System.out.println("No tasks to complete! ^_^");
return;
}
for (int i = 0; i < size; i++) {
System.out.println(i + 1 + ". " + list.get(i));
}
lineOne();
}

public static void main(String[] args) throws DukeExceptions, IOException {
Scanner sc = new Scanner(System.in);
int num = 0;
ArrayList<Task> lists = new ArrayList<Task>();
loadFromFile(lists);
lineOne();
System.out.println("Hi! I'm Halloumi ^_^");
System.out.println("What do you need help with today?");
lineOne();
do {
String text = sc.nextLine();
String[] textSplitOne = text.split("/"); //by and at
String[] textSplit = textSplitOne[0].split(" ");
String fullDesc = makeDesc(textSplit, textSplit.length);
try {
switch (textSplit[0]) {
Copy link

Choose a reason for hiding this comment

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

For case clauses, there is no indentation

case "bye":
num = exitHalloumi();
break;
case "list":
printList(lists, lists.size());
break;
case "mark":
lineOne();
System.out.println("Good Job! ^_^");
System.out.println("Task number " + textSplit[1] + " has been marked as done!");
int tNum = Integer.parseInt(textSplit[1]);
lists.get(tNum - 1).done();
System.out.println(lists.get(tNum - 1));
lineOne();
break;
case "unmark":
lineOne();
System.out.println("I've unmarked task number " + textSplit[1]);
System.out.println("Complete it soon! ^_^");
int tNo = Integer.parseInt(textSplit[1]);
lists.get(tNo - 1).undo();
System.out.println(lists.get(tNo - 1));
lineOne();
break;
case "delete" :
lineOne();
System.out.println("Noted. I've removed this task:");
//System.out.println("Complete it soon! ^_^");
int t2No = Integer.parseInt(textSplit[1]);
System.out.println(lists.get(t2No - 1));
lists.remove(t2No - 1);
lineOne();
break;
case "todo":
try {
if(fullDesc.equals(" ") || fullDesc.equals("")) {
throw new DukeInvalidTodo();
}
}
catch(DukeInvalidTodo e) {
System.err.println(e.getMessage());
continue;
}
lineTwo();
System.out.println("New task added:");
Task t = new ToDo(fullDesc);
lists.add(t);
System.out.println(t);
System.out.println("You have " + lists.size() + " tasks left now! ^_^");
lineTwo();
break;
case "event":
lineTwo();
System.out.println("New task added:");
Task t1 = new Event(fullDesc, textSplitOne[1]);
lists.add(t1);
System.out.println(t1);
System.out.println("You have " + lists.size() + " tasks left now! ^_^");
lineTwo();
break;
case "deadline":
Copy link

Choose a reason for hiding this comment

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

Logical units within a block should be separated by a line, perhaps a space after each case would be ideal!

lineTwo();
System.out.println("New task added:");
String[] date = textSplitOne[1].split(" ");
Task t2 = new Deadline(fullDesc, LocalDate.parse(date[1]));
lists.add(t2);
System.out.println(t2);
System.out.println("You have " + lists.size() + " tasks left now! ^_^");
lineTwo();
break;
default:
throw new DukeInvalidInput();

}
} catch (DukeInvalidInput e) {
System.err.println(e.getMessage());
}
}
while (num == 0) ;
writeToFile(lists);
}
}

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

public class Task {
String description;
boolean isDone;

public Task(String desc) {
description = desc;
isDone = false;
}
public String getStatusIcon() {
return (isDone ? "X" : " "); // mark done task with X
}

public String toString() {
return String.format("[%s] %s", getStatusIcon(), description);
}

public void done() {
isDone = true;
}

public void undo() {
isDone = false;
}
}

class ToDo extends Task {

Choose a reason for hiding this comment

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

I like how the code has been indented

public ToDo(String desc) {
super(desc);
}

public String toString() {
return "[T]" + super.toString();
}
}

class Event extends Task {
String at;

public Event(String desc, String b) {
super(desc);
at = b;
}
public String toString() {
return "[E]" + super.toString() + " (: " + at + ")";
}
}

class Deadline extends Task {
LocalDate when;

public Deadline(String desc, LocalDate date) {
super(desc);
when = date;
}
public String toString() {
return "[D]" + super.toString() + " (: " +
Copy link

Choose a reason for hiding this comment

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

A good practice would be to place a line break before an operator! Good use of line break to improve readability

when.format(DateTimeFormatter.ofPattern("MMM d yyyy")) + ")";
}
}
7 changes: 7 additions & 0 deletions src/main/java/exceptions/DukeExceptions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package exceptions;

public class DukeExceptions extends Exception {
public DukeExceptions(String output) {
super(output);
}
}
7 changes: 7 additions & 0 deletions src/main/java/exceptions/DukeInvalidInput.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package exceptions;

public class DukeInvalidInput extends DukeExceptions {
public DukeInvalidInput() {
super("ENTER A VALID INPUT! ^_^");
}
}
7 changes: 7 additions & 0 deletions src/main/java/exceptions/DukeInvalidTodo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package exceptions;

public class DukeInvalidTodo extends DukeExceptions {
public DukeInvalidTodo() {
super("ENTER A DESCRIPTION! ^_^");
}
}
31 changes: 24 additions & 7 deletions text-ui-test/EXPECTED.TXT
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
Hello from
____ _
| _ \ _ _| | _____
| | | | | | | |/ / _ \
| |_| | |_| | < __/
|____/ \__,_|_|\_\___|

*************************************************************************
Hi! I'm Halloumi ^_^
What do you need help with today?
*************************************************************************
|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|
New task added:
[T][ ] borrow book
You have 1 tasks in the list now! ^_^
|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|
|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|
New task added:
[E][ ] wake up (: at 8am)
You have 2 tasks in the list now! ^_^
|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|
|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|
New task added:
[D][ ] submit assignment (: by Sunday)
You have 3 tasks in the list now! ^_^
|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|
1. [T][ ] borrow book
2. [E][ ] wake up (: at 8am)
3. [D][ ] submit assignment (: by Sunday)
See you soon! Have a good day ^_^
*************************************************************************
5 changes: 5 additions & 0 deletions text-ui-test/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
todo borrow book
event wake up /at 8am
deadline submit assignment /by Sunday
list
bye
Empty file modified text-ui-test/runtest.sh
100644 → 100755
Empty file.