-
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
Mor Ben Ami #66
base: master
Are you sure you want to change the base?
Mor Ben Ami #66
Changes from 7 commits
3936521
2441777
d9d4dd1
457aa97
9a93152
663e04a
ebce00b
9b10885
fa0a0b7
3014403
a75f0e9
384558f
1863a24
4415c2e
cc20b63
9aea67a
96e1a6a
ffefb0f
62c739f
4cea348
72f1c66
11ac390
76f79c2
31ee941
e88fde8
b7f67af
586a162
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 + ")"; | ||
} | ||
|
||
} |
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")){ | ||
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(); | ||
} | ||
|
||
} |
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 + ")"; | ||
} | ||
|
||
} |
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]; | ||
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. The use of magic number here is ambiguous, feel free to consider using a constant 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. 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]; | ||
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. Avoid recycling variable. Consider declaring another variable |
||
} | ||
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(); | ||
} | ||
|
||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
public class Message { | ||
public static void printingGreeting() { | ||
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. Consider naming the function's name as |
||
printingHorizontalLine(); | ||
System.out.println("Hello I'm Duke"); | ||
System.out.println("Hello what can I do for you?"); | ||
printingHorizontalLine(); | ||
} | ||
|
||
public static void printingExit() { | ||
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. May change the function name to |
||
printingHorizontalLine(); | ||
System.out.println("Bye. Hope to see you soon"); | ||
printingHorizontalLine(); | ||
} | ||
|
||
public static void printingHorizontalLine() { | ||
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. May change the function name to |
||
System.out.println("-----------------------------------------------------------"); | ||
} | ||
|
||
public static void printingEcho(String line) { | ||
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. May change the function name to |
||
printingHorizontalLine(); | ||
System.out.println(line); | ||
printingHorizontalLine(); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
public class Task { | ||
private String description; | ||
private boolean marking; | ||
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. boolean values should be named to sound like booleans, consider "isMarked" or "isFinished" 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. Consider changing the naming of the boolean variable to "isXXX". |
||
|
||
public Task(String description) { | ||
this.description = description; | ||
marking = false; | ||
} | ||
|
||
public void markDone() { | ||
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. 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; | ||
} | ||
|
||
} |
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(); | ||
} | ||
} |
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.
Consider using a switch-case statement for neatness