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

[Sebastian Soewanto] iP #205

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
12 changes: 12 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
public class Deadline extends Task {
protected String by;

public Deadline(String description, String by) {
super(description);
this.by = by;
}
@Override
public String toString() {
return "[D]" + super.toString() + "(by: " + by + ")";
}
}
54 changes: 54 additions & 0 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,64 @@
import java.util.Scanner;

public class Duke {
public static void main(String[] args) {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";

String line = "____________________________________________________\n";
Copy link

@DavidVin357 DavidVin357 Feb 1, 2023

Choose a reason for hiding this comment

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

Seems like it is a constant, so maybe consider using static final LINE_DIVIDER (or some other similar name)?

Copy link

Choose a reason for hiding this comment

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

Naming can be changed to avoid confusion down the code block, could change to -> e.g. 'static final String margin' (since its a repeating string pattern to be printed out)

Copy link

Choose a reason for hiding this comment

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

Constant should be named by CAPITAL LETTER for example String DIVIDER, String LOGO

System.out.println("Hello from\n" + logo);
System.out.print(line + "Hello! I'm Duke\n" + "What can I do for you?\n" + line);
Task[] task = new Task[100];
Copy link

Choose a reason for hiding this comment

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

since the number of task can be more than 100. you can consider to use the dynamic size array list

Copy link

Choose a reason for hiding this comment

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

task should be renamed to tasks (with s)

int taskCount = 0;
int errorCount = 0;
while(true) {
Scanner userInput = new Scanner(System.in);
String input = userInput.nextLine();
if (input.equals("bye")) {
System.out.print(line + "Bye. Hope to see you again soon!\n" + line);
break;
} else if (input.startsWith("mark")) {
int mark = Integer.parseInt(input.substring(5));
task[mark - 1].markDone();
System.out.print(line);
} else if (input.startsWith("unmark")) {
int unmark = Integer.parseInt(input.substring(7));
Copy link

Choose a reason for hiding this comment

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

The naming of ' unmark' is a bit confusing, maybe switch to ' taskToUnmark '?

task[unmark - 1].umarkDone();
System.out.print(line);
} else if (input.equals("list")) {
System.out.print(line + "Here are the tasks in your list:\n");
for (int i = 0; i < taskCount; i++) {
System.out.println(i + 1 + "." + task[i]);
}
System.out.print(line);
} else if (input.startsWith("todo")) {
task[taskCount] = new Todo(input.substring(5));
taskCount++;
System.out.println(line + "Got it. I've added this task:\n" + task[taskCount - 1]);
System.out.print("Now you have " + taskCount + " tasks in the list.\n" + line);
} else if (input.startsWith("deadline")) {
int byIndex = input.indexOf("/by");
task[taskCount] = new Deadline(input.substring(9, byIndex), input.substring(byIndex + 4));
taskCount++;
System.out.println(line + "Got it. I've added this task:\n" + task[taskCount - 1]);
System.out.print("Now you have " + taskCount + " tasks in the list.\n" + line);
} else if (input.startsWith("event")) {
int fromIndex = input.indexOf("/from");
int toIndex = input.indexOf("/to");
task[taskCount] = new Event(input.substring(6, fromIndex), input.substring(fromIndex + 6, toIndex), input.substring(toIndex + 4));
taskCount++;
System.out.println(line + "Got it. I've added this task:\n" + task[taskCount - 1]);
System.out.print("Now you have " + taskCount + " tasks in the list.\n" + line);
} else if (errorCount == 10) {
System.out.print(line +"Maybe you can try in another language. Goodbye!\n" + line);
break;
} else {
System.out.print(line + "Sorry, could you please repeat what you just said\n" + line);
errorCount++;
}
}
}
}
16 changes: 16 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
public class Event extends Task {

protected String from;
protected String to;

public Event(String description, String from, String to) {
super(description);
this.from = from;
this.to = to;
}

@Override
public String toString() {
return "[E]" + super.toString() + "(from: " + from + "to: " + to + ")";
}
}
36 changes: 36 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
public class Task {
protected String description;
protected boolean isDone;

public Task(String description) {
this.isDone = false;
this.description = description;
}

public void markDone() {
isDone = true;
System.out.println("Nice! I've marked this task as done:\n" + this);
}

public void umarkDone() {
isDone = false;
System.out.println("OK, I've marked this task as not done yet:\n" + this);
}
public String getDescription() {
return description;
}

public String status(){
if(isDone) {
return "X";
}
else {
return " ";
}
}

@Override
public String toString() {
return "[" + status() + "]" + getDescription();
}
}
11 changes: 11 additions & 0 deletions src/main/java/Todo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
public class Todo extends Task {

public Todo(String description) {
super(description);
}

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