-
Notifications
You must be signed in to change notification settings - Fork 77
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
[Bian Rui] iP #60
Open
Brominne
wants to merge
24
commits into
nus-cs2113-AY2223S1:master
Choose a base branch
from
Brominne:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[Bian Rui] iP #60
Changes from 15 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
0878a05
Add greet and bye
17a6ed3
Add echo
c204462
Add storage class and its methods
dc31f7b
Add tasks class and mark/unmark feature
79a4cae
Refactor Level-3
139a222
Add Level-4, subtasks of task(todo, event, deadline)
cf7995e
Improve code quality: define constants and rename some variables
35d0730
Add comments
2ce92b7
Add comments
450413a
implement exceptions to handle common errors
54040a0
Typo and format fix
4d49863
Add delete task
f9b6498
Add load and save file feature
3e1a67b
Merge level-6 to master
499e447
Merge branch 'branch-Level-7'
31710f5
Set up jar files
4fd1788
More oop, and jar enabled
bfdf8f7
update comments
34488bc
update find method
453a1d2
Merge pull request #1 from Brominne/branch-Level-9
Brominne b37ea96
update user guide
0ae0f8d
fix user guide format
1056d7a
Finalised version
e0b9547
Fix directory problem on windows
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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 |
---|---|---|
|
@@ -15,3 +15,4 @@ bin/ | |
|
||
/text-ui-test/ACTUAL.txt | ||
text-ui-test/EXPECTED-UNIX.TXT | ||
/text-ui-test/runtest.sh |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
T | 1 | todo | ||
D | 0 | deadline | sometime | ||
E | 0 | event | now |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
T | 1 | todo | ||
D | 0 | deadline | sometime | ||
E | 0 | event | now | ||
T | 0 | kkk |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
public class CorruptedDataFileException extends Exception{ | ||
} |
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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
public class Deadline extends Task implements FormatChecker { | ||
private static final String DEADLINE_MARK = "[D]"; | ||
private static final String taskType = "D"; | ||
private String time; | ||
|
||
/** | ||
* Default constructor for Deadline instance | ||
* | ||
* @param description description of Deadline | ||
* @param time time of deadline | ||
*/ | ||
public Deadline(String description, String time) { | ||
super(description); | ||
this.time = time; | ||
} | ||
|
||
/** | ||
* Constructor for a raw string input of deadline | ||
* | ||
* @param complexString raw string containing description and deadline | ||
*/ | ||
public Deadline(String complexString) throws WrongCommandFormatException { | ||
super(); | ||
try { | ||
int identifierIndex = FormatChecker.findIdentifierIndex(DEADLINE_IDENTIFIER, complexString); | ||
this.description = complexString.substring(0, identifierIndex); | ||
FormatChecker.checkNullString(this.description); | ||
this.time = complexString.substring(identifierIndex + TIME_IDENTIFIER_LENGTH); | ||
FormatChecker.checkNullString(this.time); | ||
this.isDone = false; | ||
} catch (WrongCommandFormatException e) { | ||
throw new WrongCommandFormatException(); | ||
} | ||
} | ||
|
||
public Deadline(String description, Boolean isDone, String time) { | ||
this.description = description; | ||
this.isDone = isDone; | ||
this.time = time; | ||
} | ||
|
||
@Override | ||
public String getStatusIcon() { | ||
return DEADLINE_MARK + super.getStatusIcon(); | ||
} | ||
|
||
@Override | ||
public String getTaskType() { | ||
return taskType; | ||
} | ||
|
||
@Override | ||
public String getTime() { | ||
return this.time; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.format("%s %s(by: %s)", this.getStatusIcon(), description, this.time); | ||
} | ||
} |
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,10 +1,70 @@ | ||
import java.util.Scanner; | ||
|
||
public class Duke { | ||
|
||
private static final String COMMAND_BYE = "bye"; | ||
private static final String BYE_MESSAGE = "Bye! Always there waiting for you!"; | ||
private static final String GREET_MESSAGE_1 = "Hello! I'm Rae."; | ||
private static final String GREET_MESSAGE_2 = "How does everything progress now?"; | ||
private static final int LINE_SEPARATOR_LENGTH = 60; | ||
private static final String LINE_SEPARATOR = "_"; | ||
|
||
public static void separateLine() { | ||
System.out.println(LINE_SEPARATOR.repeat(LINE_SEPARATOR_LENGTH)); | ||
} | ||
|
||
/** | ||
* greet prints greet messages | ||
*/ | ||
public static void greet() { | ||
separateLine(); | ||
System.out.println(GREET_MESSAGE_1); | ||
System.out.println(GREET_MESSAGE_2); | ||
} | ||
|
||
/** | ||
* bye prints farewell messages | ||
*/ | ||
public static void bye() { | ||
separateLine(); | ||
System.out.println(BYE_MESSAGE); | ||
separateLine(); | ||
} | ||
|
||
/** | ||
* echo print input string with line breaker after it | ||
* | ||
* @param line the line of string input | ||
*/ | ||
public static void echo(String line) { | ||
separateLine(); | ||
System.out.println(line); | ||
separateLine(); | ||
} | ||
|
||
|
||
public static void main(String[] args) { | ||
String logo = " ____ _ \n" | ||
+ "| _ \\ _ _| | _____ \n" | ||
+ "| | | | | | | |/ / _ \\\n" | ||
+ "| |_| | |_| | < __/\n" | ||
+ "|____/ \\__,_|_|\\_\\___|\n"; | ||
System.out.println("Hello from\n" + logo); | ||
greet(); | ||
Storage storage = new Storage(); | ||
storage.loadSave(); | ||
separateLine(); | ||
Scanner in = new Scanner(System.in); | ||
String line = in.nextLine(); | ||
|
||
while (!line.equalsIgnoreCase(COMMAND_BYE)) { | ||
separateLine(); | ||
try { | ||
storage.execute(line); | ||
} catch (UnknownCommandException e) { | ||
System.out.format("Exception: Unknown command%n" + | ||
"%s is not a valid command%n", line.split(" ")[0]); | ||
} catch (NullCommandException e) { | ||
System.out.format("Exception: Null command%n" + | ||
"No command is entered%n"); | ||
} | ||
separateLine(); | ||
line = in.nextLine(); | ||
} | ||
bye(); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
public class Event extends Task implements FormatChecker { | ||
private static final String EVENT_MARK = "[E]"; | ||
private static final String taskType = "E"; | ||
private String time; | ||
|
||
/** | ||
* Default constructor for Event instance | ||
* | ||
* @param description description of Event | ||
* @param time time of event | ||
*/ | ||
public Event(String description, String time) { | ||
super(description); | ||
this.time = time; | ||
} | ||
|
||
/** | ||
* Event constructor for a raw string input of event | ||
* | ||
* @param complexString raw string input containing time and description of event | ||
*/ | ||
public Event(String complexString) throws WrongCommandFormatException { | ||
super(); | ||
try { | ||
int identifierIndex = FormatChecker.findIdentifierIndex(EVENT_IDENTIFIER, complexString); | ||
this.description = complexString.substring(0, identifierIndex); | ||
FormatChecker.checkNullString(this.description); | ||
this.time = complexString.substring(identifierIndex + TIME_IDENTIFIER_LENGTH); | ||
FormatChecker.checkNullString(this.time); | ||
this.isDone = false; | ||
} catch (WrongCommandFormatException e) { | ||
throw new WrongCommandFormatException(); | ||
} | ||
} | ||
|
||
public Event(String description, Boolean isDone, String time) { | ||
this.description = description; | ||
this.isDone = isDone; | ||
this.time = time; | ||
} | ||
|
||
@Override | ||
public String getStatusIcon() { | ||
return EVENT_MARK + super.getStatusIcon(); | ||
} | ||
|
||
@Override | ||
public String getTaskType() { | ||
return taskType; | ||
} | ||
|
||
@Override | ||
public String getTime() { | ||
return this.time; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.format("%s %s(at: %s)", this.getStatusIcon(), description, this.time); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
public class ExcessArgumentException extends Exception { | ||
} |
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
import java.util.ArrayList; | ||
import java.util.Scanner; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
|
||
public interface FileIO { | ||
|
||
static ArrayList<Task> loadFile() throws CorruptedDataFileException, FileNotFoundException { | ||
File file = new File("/Users/bromine/ip/Saves/Tasks"); | ||
Scanner sc = new Scanner(file); | ||
|
||
ArrayList<Task> tasks = new ArrayList<>(); | ||
while (sc.hasNext()) { | ||
String line = sc.nextLine(); | ||
|
||
String[] args = line.split(" | ", 0); | ||
|
||
String taskType = args[0]; | ||
String description = args[4]; | ||
String time = (args.length > 5 ? args[6] : ""); | ||
Boolean isDone = (Integer.parseInt(args[2]) == 1); | ||
|
||
switch (taskType) { | ||
case "T": | ||
tasks.add(new Todo(description, isDone)); | ||
break; | ||
case "D": | ||
tasks.add(new Deadline(description, isDone, time)); | ||
break; | ||
case "E": | ||
tasks.add(new Event(description, isDone, time)); | ||
break; | ||
default: | ||
throw new CorruptedDataFileException(); | ||
} | ||
} | ||
|
||
return tasks; | ||
} | ||
|
||
static void writeFile(ArrayList<Task> Tasks) throws IOException { | ||
FileWriter fw = new FileWriter("/Users/bromine/ip/Saves/Tasks"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems the |
||
StringBuilder taskFileFormat = new StringBuilder(); | ||
|
||
for (Task task : Tasks) { | ||
taskFileFormat.append(task.getTaskType()).append(" | ") | ||
.append(task.getIsDone() ? "1" : "0").append(" | ").append(task.getDescription()); | ||
if (!task.getTaskType().equals("T")) { | ||
taskFileFormat.append(" | ").append(task.getTime()); | ||
} | ||
taskFileFormat.append(String.format("%n")); | ||
} | ||
fw.write(taskFileFormat.toString()); | ||
fw.close(); | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
public interface FormatChecker { | ||
|
||
int TIME_IDENTIFIER_LENGTH = 5; | ||
|
||
static void checkNullString(String string) throws WrongCommandFormatException { | ||
if (string.replaceAll("\\s+", "").equals("")) { | ||
throw new WrongCommandFormatException(); | ||
} | ||
} | ||
|
||
static int findIdentifierIndex(String identifier, String complexString) throws WrongCommandFormatException { | ||
int separatorIndex = complexString.indexOf(identifier); | ||
if (separatorIndex == -1) { | ||
throw new WrongCommandFormatException(); | ||
} | ||
return separatorIndex; | ||
} | ||
|
||
static void checkExcessArgument(String cmd) throws ExcessArgumentException { | ||
if (cmd.split(" ").length > 2) { | ||
throw new ExcessArgumentException(); | ||
} | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
public class NullArgumentException extends Exception { | ||
} |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
public class NullCommandException extends Exception{ | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps you can avoid the unnecessary use of
this
.https://se-education.org/guides/conventions/java/index.html#variables