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

Mor Ben Ami #66

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

public Deadline(String description, String date) {
super(description);
this.date = date;
}

@Override
public String toString() {
return "[D][" + getMarking() + "] " + getDescription() + " (by: " + date + ")";
}

}
30 changes: 30 additions & 0 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,40 @@
import java.util.Scanner;

public class Duke {

public static void main(String[] args) {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
Message.printingGreeting();
echo();
}

public static void echo(){
List dukeList = new List();
String[] words;
String line;
Scanner in = new Scanner(System.in);
line = in.nextLine();
while (!line.equals("bye")){
words = line.split(" ");
if (line.equals("list")){

Choose a reason for hiding this comment

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

Consider using a switch-case statement for neatness

dukeList.printingList();
} else if (words[0].equals("unmark")){
int TaskNumber = Integer.parseInt(words[1]);
dukeList.unmarkingItem(TaskNumber);
} else if (words[0].equals("mark")) {
int TaskNumber = Integer.parseInt(words[1]);
dukeList.markingItem(TaskNumber);
} else {
dukeList.addTask(line);
}
line = in.nextLine();
}
Message.printingExit();
}

}
14 changes: 14 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
public class Event extends Task {
private String date;

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

@Override
public String toString() {
return "[E][" + getMarking() + "] " + getDescription() + " (at: " + date + ")";
}

}
61 changes: 61 additions & 0 deletions src/main/java/List.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
public class List {
private static int amountOfItems = 0;
private static Task[] tasks;


public List() {
tasks = new Task[100];

Choose a reason for hiding this comment

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

The use of magic number here is ambiguous, feel free to consider using a constant

Choose a reason for hiding this comment

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

Avoid using magic literals. Consider declaring a constant for it.

}

public int getListSize() {
return amountOfItems;
}

public void addTask(String input) {
if (input.contains("/by") || input.split(" ")[0].equals("deadline")) {
if (input.split(" ", 2)[0].equals("deadline")) {
input = input.split(" ", 2)[1];

Choose a reason for hiding this comment

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

Avoid recycling variable. Consider declaring another variable String description to store instead of using input again.

}
String[] details = input.split(" /by ");
tasks[amountOfItems] = new Deadline(details[0], details[1]);
tasks[amountOfItems] = new Deadline(details[0], details[1]);
} else if (input.contains("/at") || input.split(" ")[0].equals("event")) {
if (input.split(" ", 2)[0].equals("event")) {
input = input.split(" ", 2)[1];
}
String[] details = input.split(" /at ");
tasks[amountOfItems] = new Event(details[0], details[1]);
} else {
if (input.split(" ", 2)[0].equals("todo")) {
input = input.split(" ", 2)[1];
}
tasks[amountOfItems] = new Todo(input);
}
Message.printingHorizontalLine();
System.out.println("Got it. I've added this task:");
System.out.println(tasks[amountOfItems]);
System.out.println("Now you have " + (amountOfItems + 1) + " tasks in the list.");
Message.printingHorizontalLine();
amountOfItems++;
}

public void printingList() {
Message.printingHorizontalLine();
System.out.println("Here are the tasks in your list:");
for (int i = 0; i < amountOfItems; i++) {
System.out.print(i + 1 + ". ");
System.out.println(tasks[i]);
}
Message.printingHorizontalLine();
}

public void markingItem(int i) {
tasks[i-1].markDone();
}

public void unmarkingItem(int i) {
tasks[i-1].unmarkDone();
}


}
25 changes: 25 additions & 0 deletions src/main/java/Message.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
public class Message {
public static void printingGreeting() {

Choose a reason for hiding this comment

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

Consider naming the function's name as printGreeting() instead of printingGreeting().

printingHorizontalLine();
System.out.println("Hello I'm Duke");
System.out.println("Hello what can I do for you?");
printingHorizontalLine();
}

public static void printingExit() {

Choose a reason for hiding this comment

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

May change the function name to printExit()

printingHorizontalLine();
System.out.println("Bye. Hope to see you soon");
printingHorizontalLine();
}

public static void printingHorizontalLine() {

Choose a reason for hiding this comment

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

May change the function name to printHorizontalLine()

System.out.println("-----------------------------------------------------------");
}

public static void printingEcho(String line) {

Choose a reason for hiding this comment

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

May change the function name to printEcho()

printingHorizontalLine();
System.out.println(line);
printingHorizontalLine();
}

}
33 changes: 33 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
public class Task {
private String description;
private boolean marking;

Choose a reason for hiding this comment

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

boolean values should be named to sound like booleans, consider "isMarked" or "isFinished"

Choose a reason for hiding this comment

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

Consider changing the naming of the boolean variable to "isXXX".


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

public void markDone() {

Choose a reason for hiding this comment

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

Perhaps it would be better to have a method to print the string, rather than having a function that does both setting the boolean and printing

System.out.println("Nice! I've marked this task as done:");
marking = true;
System.out.println(" [X] " + description);
}

public void unmarkDone() {
System.out.println(" OK, I've marked this task as not done yet:");
marking = false;
System.out.println(" [ ] " + marking);
}

public String getMarking() {
if (marking) {
return "X";
}
return " ";
}

public String getDescription() {
return description;
}

}
10 changes: 10 additions & 0 deletions src/main/java/Todo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
public class Todo extends Task {
public Todo(String description) {
super(description);
}

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