forked from nus-cs2113-AY2324S1/ip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
317108a
commit 898968d
Showing
5 changed files
with
139 additions
and
26 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,30 @@ | ||
package dude; | ||
|
||
public class Deadline extends Task { | ||
String by; | ||
private String by; | ||
|
||
// Constructor to initialize a deadline with a description and a due date | ||
public Deadline(String description, String by) { | ||
super(description); | ||
this.by = by; | ||
this.type = "[D]"; // Type [D] indicates this is a dude.Deadline | ||
this.type = "[D]"; | ||
} | ||
|
||
@Override | ||
public String toFileFormat() { | ||
return super.toFileFormat() + " | " + by; | ||
} | ||
|
||
public static Deadline fromFileFormat(String fileString) { | ||
String[] parts = fileString.split("\\s\\|\\s"); | ||
Deadline deadline = new Deadline(parts[2], parts[3]); | ||
if (parts[1].equals("1")) { | ||
deadline.markAsDone(); | ||
} | ||
return deadline; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return getType() + getStatusIcon() + " " + description + " (by: " + by + ")"; | ||
return super.toString() + " (by: " + by + ")"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,32 @@ | ||
package dude; | ||
|
||
public class Event extends Task { | ||
String startDate; | ||
String endDate; | ||
private String from; | ||
private String to; | ||
|
||
// Constructor to initialize an event with a description, start date, and end date | ||
public Event(String description, String startDate, String endDate) { | ||
public Event(String description, String from, String to) { | ||
super(description); | ||
this.startDate = startDate; | ||
this.endDate = endDate; | ||
this.type = "[E]"; // Type [E] indicates this is an dude.Event | ||
this.from = from; | ||
this.to = to; | ||
this.type = "[E]"; | ||
} | ||
|
||
@Override | ||
public String toFileFormat() { | ||
return super.toFileFormat() + " | " + from + " | " + to; | ||
} | ||
|
||
public static Event fromFileFormat(String fileString) { | ||
String[] parts = fileString.split("\\s\\|\\s"); | ||
Event event = new Event(parts[2], parts[3], parts[4]); | ||
if (parts[1].equals("1")) { | ||
event.markAsDone(); | ||
} | ||
return event; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return getType() + getStatusIcon() + " " + description + " (from: " + startDate + " to: " + endDate + ")"; | ||
return super.toString() + " (from: " + from + " to: " + to + ")"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,43 @@ | ||
package dude; | ||
|
||
public class Task { | ||
// Instance variables to store task description and status | ||
protected String description; | ||
protected boolean isDone; | ||
protected String type; | ||
|
||
// Constructor to initialize a task with a description | ||
public Task(String description) { | ||
this.description = description; | ||
this.isDone = false; | ||
this.type = "[T]"; // Default type is [T] | ||
this.type = "[T]"; // Represents a generic task. | ||
} | ||
|
||
public String getType() { | ||
return type; | ||
} | ||
|
||
// Method to get the status icon based on whether the task is done or not | ||
public String getStatusIcon() { | ||
return (isDone ? "[X]" : "[ ]"); | ||
} | ||
|
||
public String getDescription() { | ||
return description; | ||
} | ||
|
||
public void markAsDone() { | ||
isDone = true; | ||
} | ||
|
||
public String toFileFormat() { | ||
return type.charAt(1) + " | " + (isDone ? "1" : "0") + " | " + description; | ||
} | ||
|
||
public static Task fromFileFormat(String fileString) { | ||
String[] parts = fileString.split("\\s\\|\\s"); | ||
Task task = new Task(parts[2]); | ||
if (parts[1].equals("1")) { | ||
task.markAsDone(); | ||
} | ||
return task; | ||
} | ||
|
||
@Override | ||
public String toString () { | ||
return getType() + getStatusIcon() + " " + description; | ||
public String toString() { | ||
return type + getStatusIcon() + " " + description; | ||
} | ||
} |