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

[Zhitong] ip #110

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
Binary file added production/ip/Commands.class
Binary file not shown.
Binary file added production/ip/MrStripes.class
Binary file not shown.
Binary file added production/ip/Texts.class
Binary file not shown.
60 changes: 60 additions & 0 deletions src/main/java/Commands.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@


public class Commands {

private static final int MAX_LENGTH = 100;
private Task[] tasks = new Task[MAX_LENGTH];

public int length = 0;

private boolean isExited = false;

Choose a reason for hiding this comment

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

Shouldn't the private attributes be grouped together?


public Commands() {

}

public void accept(String nextLine) {

int index = (nextLine.indexOf(' '));
String commandKeyword = (index == -1)? nextLine : nextLine.substring(0, index).trim();

Choose a reason for hiding this comment

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

Should there be a space before the "?" ternary operator?


final String commandText = (index == -1)? nextLine : nextLine.substring(index).trim();

Choose a reason for hiding this comment

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

Shouldn't you extract this magic number?

switch (commandKeyword) {
case "exit" -> this.isExited = true;
case "list" -> this.list();
case "add" -> {
this.tasks[length] = new Task(nextLine.substring(index));
this.echo();
length++;
}
case "mark" -> {
this.tasks[Integer.parseInt(commandText)].setDone(true);
echo(Integer.parseInt(commandText));
}
case "unmark" -> {
this.tasks[Integer.parseInt(commandText)].setDone(false);
echo(Integer.parseInt(commandText));
}
}

}


private void list() {
for (int i = 0; i < length; i++) {
System.out.println( i +": "+ tasks[i]);
}
}

private void echo() {
System.out.println("added: " + tasks[length]);
}
private void echo( int index) {
System.out.println(tasks[index]);
}

public boolean isAcceptingCommands () {
return !isExited;
}

}
10 changes: 0 additions & 10 deletions src/main/java/Duke.java

This file was deleted.

18 changes: 18 additions & 0 deletions src/main/java/MrStripes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@


import java.util.Scanner;

public class MrStripes {
public static void main(String[] args) {

System.out.println(Texts.GREETINGS);

Scanner scanner = new Scanner(System.in);
Commands commands = new Commands();
while (commands.isAcceptingCommands()) {
commands.accept(scanner.nextLine());
}

System.out.println(Texts.GOODBYE);
}
}
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 {
private String line;
private boolean isDone;

public String getLine() {
return line;
}

public void setLine(String line) {
this.line = line;
}

public boolean isDone() {
return isDone;
}

public void setDone(boolean done) {
isDone = done;
}

public Task(String line, boolean isDone) {
this.line = line;
this.isDone = isDone;
}

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

@Override
public String toString() {
return "[" + (isDone? "X" : " ") + "]"
+ line;

Choose a reason for hiding this comment

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

Shouldn't this be on the same line (line limit 110 characters)?

}
}
6 changes: 6 additions & 0 deletions src/main/java/Texts.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

public class Texts {
public static final String GREETINGS = " hello";

Choose a reason for hiding this comment

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

I like how you use all caps for constants.

public static final String GOODBYE = "goodbye";

}