Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
6169785
Level 0: adding greetLine and exitLine
wangsilangchange-hash Jan 27, 2023
d047c4e
Level 1: Adding echo function
wangsilangchange-hash Jan 27, 2023
b1f3481
Level 1,2: Rectify mistake in echo, where "bye" will also be echoed. …
wangsilangchange-hash Jan 27, 2023
e45b36b
Level 3: Complete level 3, add in printCurrentList function.
wangsilangchange-hash Jan 27, 2023
fbf03b0
Level 4 complete
wangsilangchange-hash Feb 3, 2023
9ac72cf
Level 5 complete
wangsilangchange-hash Feb 9, 2023
90cbc52
A-Packages
wangsilangchange-hash Feb 9, 2023
4eee682
Level 6 Complete
wangsilangchange-hash Feb 15, 2023
21815d8
Revert "Level 6 Complete"
wangsilangchange-hash Feb 15, 2023
21238c7
Revert "Revert "Level 6 Complete""
wangsilangchange-hash Feb 15, 2023
d5393f2
Fixing going back to master
wangsilangchange-hash Feb 17, 2023
55e06c9
Merge branch 'master' into branch-Level-6
wangsilangchange-hash Feb 17, 2023
d98e800
Level 7 complete
wangsilangchange-hash Feb 17, 2023
a9eebd0
A-Jar
wangsilangchange-hash Feb 17, 2023
7688011
A-MoreOOP
wangsilangchange-hash Mar 3, 2023
c240a47
Level-9, A-JavaDoc
wangsilangchange-hash Mar 3, 2023
fde76d5
Create user guide for Duke
JangusRoundstone Mar 3, 2023
da82fc2
Merge commit 'fde76d508d756f10c50396b0d6398fed4f2da62d' into branch-L…
wangsilangchange-hash Mar 3, 2023
d9e6240
Merge pull request #1 from JangusRoundstone/branch-Level-7
JangusRoundstone Mar 5, 2023
e202337
branch-Level-9
wangsilangchange-hash Mar 5, 2023
806f874
branch-A-JavaDoc
wangsilangchange-hash Mar 5, 2023
4b7e1b8
Merge pull request #2 from JangusRoundstone/branch-A-JavaDoc
JangusRoundstone Mar 5, 2023
d703de1
Merge tag 'branch-Level-9'
wangsilangchange-hash Mar 5, 2023
399c136
Published UG
wangsilangchange-hash Mar 5, 2023
d914533
Merge branch 'master' into branch-Level-9
wangsilangchange-hash Mar 5, 2023
b8552f4
Merge pull request #3 from JangusRoundstone/branch-Level-9
JangusRoundstone Mar 5, 2023
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@ Prerequisites: JDK 11, update Intellij to the most recent version.
| | | | | | | |/ / _ \
| |_| | |_| | < __/
|____/ \__,_|_|\_\___|


```

wang silang
23 changes: 23 additions & 0 deletions src/main/java/Deadlines.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
public class Deadlines extends Task {
private String endTime;
private String taskLabel = "[D]";
public Deadlines (String input){
super(input.substring(9,input.indexOf('/') - 1)); // Sanitize input by removing "deadline" at the start

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Personally, maybe you can replace the number 9 with a constant to avoid "magic numbers"?

Like private static final int DEADLINE_LABEL = 9;?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Agreed. Thanks for the idea!

super.setTaskLabel(taskLabel);
endTime = "(" + getEndTime(input) + ")";
}
// Method of StringBuffer operation taken from

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I like the way you use StringBuffer to operate on these strings, it's really useful.

// https://www.geeksforgeeks.org/insert-a-string-into-another-string-in-java/
@Override
public String getEndTime(String input){
String deadline = input.substring(input.indexOf('/') + 1); // endTime of task is the string after '/'
StringBuffer deadlineCorrectFormat = new StringBuffer(deadline); // convert to StringBuffer for inserting ':'
deadlineCorrectFormat.insert(2,":");
return deadlineCorrectFormat.toString();
}

@Override
public String toString(){
return this.taskLabel + this.mark + " " + this.description + " " + this.endTime;
}
}
87 changes: 87 additions & 0 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import jdk.jfr.Event;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

where/how is this used?


import java.util.Arrays;
import java.util.Scanner;

public class Duke {
public static void main(String[] args) {
String logo = " ____ _ \n"
Expand All @@ -6,5 +11,87 @@ public static void main(String[] args) {
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
greetLine();
addList();
exitLine();
}
public static void greetLine(){
System.out.println("How may I be of service?");
}
public static void echo()
{
String line;
Scanner in = new Scanner(System.in);
line = in.nextLine();
while(!line.equals("bye")) {
System.out.println(line);
line = in.nextLine();
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You'd want to indent the { } properly, like:
public static void echo(){

// your code
}

public static void exitLine(){
System.out.println("Glad I could be of help!");
}

public static void addList()
{

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Use K&R style brackets (as done in the exitLine method)

Task[] list = new Task[100];
String line;
Scanner in = new Scanner(System.in);
line = in.nextLine();
int numOfItems = 0;
while(!line.equals("bye")) { // condition to shut down program
if(line.equals("list")) { // users wants to know all text so far
printCurrentList(list, numOfItems);
}
else if(line.startsWith("mark")){
mark(line, list);
printCurrentList(list, numOfItems);
}
else if(line.startsWith("unmark")){
unmark(line,list);
printCurrentList(list, numOfItems);
}
else { // new tasks keyed in by user
Task newTask = new Task(line);
if(line.startsWith("todo")){
newTask = new ToDos(line);
}
else if(line.startsWith("deadline")){

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

change the form of the if/else statements to match the coding standard:

if (condition) {
statements;
} else if (condition) {
statements;
} else {
statements;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Yeah, you can refer to this link [https://se-education.org/guides/conventions/java/basic.html] for if-else statement coding standards.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks guys!

newTask = new Deadlines(line);
}
else{
newTask = new Events(line);
}
list[numOfItems] = newTask;
++numOfItems;
}
line = in.nextLine(); // read in next line of text
}
}

public static void mark(String task, Task[] list)
{
String indexOfTask = task.substring(5); // get the number of task to be marked
Task taskToBeMarked = list[Integer.parseInt(indexOfTask) - 1]; // convert from 1-based to 0-based
taskToBeMarked.markTask();
System.out.println("Sir, your task has been marked as completed.");
}

public static void unmark(String task, Task[] list)
{
String indexOfTask = task.substring(7);
Task taskToBeMarked = list[Integer.parseInt(indexOfTask) - 1]; // convert from 1-based to 0-based
taskToBeMarked.unmarkTask();
System.out.println("Sir, your task has been unmarked as requested.");
}

public static void printCurrentList(Task[] list, int numOfItems)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nice job making clear method and variable names!

{
Task[] subList = Arrays.copyOf(list, numOfItems);
System.out.println("Your current list of items as requested, sir.");
for(int i = 0; i < subList.length; ++i)
{
System.out.println(Integer.toString(i+1) + "." + subList[i]);
}
}
}
33 changes: 33 additions & 0 deletions src/main/java/Events.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
public class Events extends Task{
private String timeLine;
private String taskLabel = "[E]";
public Events (String input){
super(input.substring(6,input.indexOf('/') - 1));
super.setTaskLabel(taskLabel);
timeLine = "(" + getStartTime(input) + getEndTime(input) + ")";
}
public String[] splitInput(String input){
String[] inputAfterSplit = input.split("/", 3); // split twice to generate three strings
return inputAfterSplit;
}
@Override
public String getStartTime(String input){
String[] inputAfterSplit = splitInput(input);
String startTime = inputAfterSplit[1];
StringBuffer startTimeCorrectFormat = new StringBuffer(startTime);
startTimeCorrectFormat.insert(4,":");
return startTimeCorrectFormat.toString();
}
@Override
public String getEndTime(String input){
String[] inputAfterSplit = splitInput(input);
String startTime = inputAfterSplit[2];
StringBuffer endTimeCorrectFormat = new StringBuffer(startTime); // convert to StringBuffer for inserting ':'
endTimeCorrectFormat.insert(2,":");
return endTimeCorrectFormat.toString();
}
@Override
public String toString(){
return this.taskLabel + this.mark + " " + this.description + " " + this.timeLine;
}
}
31 changes: 31 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
public class Task {
protected String taskLabel;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I like how you have added another variable called taskLabel.

This is actually clear while storing the data in it instead of explicitly typing [D] / [E] / [T] every time while printing the lists.

protected String description;
protected String mark;
public Task(String input) {
this.description = input;
this.taskLabel = "To be replaced by labels";
this.mark = "[ ]";
}
public String getTaskLabel() {
return taskLabel;
}
public String getDescription() {
return description;
}
public String getStartTime(String input){
return "To be overridden by subclass' methods";
}
public String getEndTime(String input){
return "To be overridden by subclass' methods";
}
public void setTaskLabel(String taskLabel) {
this.taskLabel = taskLabel;
}
public void markTask(){
this.mark = "[X]";
}
public void unmarkTask(){
this.mark = "[ ]";
}
}
11 changes: 11 additions & 0 deletions src/main/java/ToDos.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
public class ToDos extends Task {
private String taskLabel = "[T]";
public ToDos (String input){
super(input.substring(5)); // for ToDos tasks, description = input
super.setTaskLabel(taskLabel);
}
@Override
public String toString(){
return this.taskLabel + this.mark + " " + this.description;
}
}
2 changes: 2 additions & 0 deletions text-ui-test/EXPECTED.TXT
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ Hello from
| |_| | |_| | < __/
|____/ \__,_|_|\_\___|

How may I be of service?
Glad I could be of help!
2 changes: 2 additions & 0 deletions text-ui-test/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
todo CS2113 assignment
bye