Skip to content

Commit

Permalink
Merge branch 'branch-Level-7'
Browse files Browse the repository at this point in the history
  • Loading branch information
gachia committed Aug 27, 2019
2 parents 804f872 + 388dd77 commit 726b245
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/main/data/duke.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
T true read book
D false return book/June 6th
D false project meeting/Aug 6th 2-4pm
T true join sports club
T true dance
D false get food/tmr
E true dance party/my place
10 changes: 10 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ public Deadline(String desc, String by) {
this.by = by;
}

public Deadline(String desc, String by, boolean isDone){
super(desc, isDone);
this.by = by;
}

@Override
public String writeFormat(){
return "D " + isDone + " " + description + "/" + by;
}

@Override
public String toString(){
return "[D]" + super.getTask() + " (by: " + by + ")";
Expand Down
56 changes: 54 additions & 2 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,50 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Scanner;
import java.util.ArrayList;
import java.io.File;
import java.io.FileWriter;

public class Duke {

private static void loadData(String filePath, ArrayList<Task> list) throws FileNotFoundException {
File f = new File(filePath);
//System.out.println(f.getAbsolutePath());
Scanner sc = new Scanner(f);
while (sc.hasNext()){
String type = sc.next();
switch(type){
case "T":
boolean done = sc.nextBoolean();
String taskName = sc.nextLine().trim();
list.add(new Task(taskName, done));
break;
case "D":
done = sc.nextBoolean();
taskName = sc.nextLine().trim();
String[] userWords = taskName.split("/");
list.add(new Deadline(userWords[0], userWords[1], done));
break;
case "E":
done = sc.nextBoolean();
taskName = sc.nextLine().trim();
userWords = taskName.split("/");
list.add(new Event(userWords[0], userWords[1], done));
break;
}
}
}

private static void saveData(String filePath, ArrayList<Task> list) throws IOException {
FileWriter fw = new FileWriter(filePath);
String data = "";
for (Task t : list){
data += t.writeFormat() + "\n";
}
fw.write(data);
fw.close();
}

public static void main(String[] args) {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
Expand All @@ -13,8 +55,14 @@ public static void main(String[] args) {
final String lineSpace = "_______________________________\n";
String startMessage = lineSpace + "Hello! I'm Duke\nWhat can I do for you?\n" + lineSpace;
System.out.println(startMessage);
Scanner sc = new Scanner(System.in);
ArrayList<Task> list = new ArrayList();
final String filePath = "src/main/data/duke.txt";
try{
loadData(filePath, list);
}catch(FileNotFoundException e){
System.out.println("File not found");
}
Scanner sc = new Scanner(System.in);
String taskName;
Task task;
while (sc.hasNext()) {
Expand Down Expand Up @@ -42,6 +90,7 @@ public static void main(String[] args) {
list.add(task);
System.out.println(lineSpace + "Got it. I've added this task:\n" + task
+ "\nNow you have " + list.size() + " tasks in the list.\n" + lineSpace);
saveData(filePath, list);
break;
case "deadline":
taskName = sc.nextLine().trim();
Expand All @@ -56,7 +105,7 @@ public static void main(String[] args) {
list.add(task);
System.out.println(lineSpace + "Got it. I've added this task:\n" + task
+ "\nNow you have " + list.size() + " tasks in the list.\n" + lineSpace);

saveData(filePath, list);
break;
case "event":
taskName = sc.nextLine().trim();
Expand All @@ -71,6 +120,7 @@ public static void main(String[] args) {
list.add(task);
System.out.println(lineSpace + "Got it. I've added this task:\n" + task
+ "\nNow you have " + list.size() + " tasks in the list.\n" + lineSpace);
saveData(filePath, list);
break;
case "delete":
int deletion = sc.nextInt();
Expand All @@ -81,6 +131,7 @@ public static void main(String[] args) {
list.remove(deletion-1);
System.out.println(lineSpace + "Noted. I've removed this task:\n" + temp
+ "\nNow you have " + list.size() + " tasks in the list.\n" + lineSpace);
saveData(filePath, list);
break;
case "done":
int taskNo = sc.nextInt();
Expand All @@ -90,6 +141,7 @@ public static void main(String[] args) {
list.get(taskNo - 1).markAsDone();
System.out.println(lineSpace + "Nice! I've marked this task as done:\n"
+ list.get(taskNo - 1) + "\n" + lineSpace);
saveData(filePath, list);
break;
default:
throw new DukeException("☹ OOPS!!! I'm sorry, but I don't know what that means :-(");
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ public Event(String desc, String at) {
this.at = at;
}

public Event(String desc, String at, boolean isDone) {
super(desc, isDone);
this.at = at;
}

@Override
public String writeFormat(){
return "E " + isDone + " " + description + "/" + at;
}

@Override
public String toString(){
return "[E]" + super.getTask() + " (at: " + at + ")";
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ public Task(String desc) {
this.isDone = false;
}

public Task(String desc, boolean isDone){
this.description = desc;
this.isDone = isDone;
}

public String getStatusIcon() {
return (isDone ? "\u2713" : "\u2718"); //return tick or X symbols
}
Expand All @@ -20,6 +25,10 @@ public String getTask(){
return output;
}

public String writeFormat(){
return "T " + isDone + " " + description;
}

@Override
public String toString(){
return "[T]" + getTask();
Expand Down

0 comments on commit 726b245

Please sign in to comment.