Skip to content
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
2 changes: 2 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
package PACKAGE_NAME;public class Deadline {
}
10 changes: 0 additions & 10 deletions src/main/java/Duke.java

This file was deleted.

2 changes: 2 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
package PACKAGE_NAME;public class Event {
}
133 changes: 133 additions & 0 deletions src/main/java/Listmanager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import java.util.Scanner;

public class Todolist {

String Icon = "T";
private static final int MAX_LIST_LENGTH = 100;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good use of constant for the max list length

static String[] todolist = new String[MAX_LIST_LENGTH];
static boolean[] isDoneList = new boolean[MAX_LIST_LENGTH];

static int ListCount= 0;
static Scanner in = new Scanner(System.in);

public static void AddToList(){

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
public static void AddToList(){
public static void AddToList() {

Take note that for function declaration, there should be a space before {

String Task= in.nextLine();
todolist[ListCount] = Task;
isDoneList[ListCount]= false;
ListCount++;
return;
}



static void HandleList(){
PrintList();
String command ="";

while(!command.equals("quit")){
command = in.nextLine();
switch (command){
case"add":

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Inconsistency in whether there is a space after case.

Suggested change
case"add":
case "add":

AddToList();
System.out.println("Task added");
PrintList();
break;
case"quit":
System.out.println("Task change complete");
break;
case"help":
System.out.print("supported commands: add , quit , help , mark,unmark ,clear, list\n");
break;
case "clear":
ClearList();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good attempt at abstracting the functionality of each command

ClearisDoneList();
System.out.print("list cleared\n");
break;
case"mark":
SetDone();
break;
case"unmark":
SetUndone();
break;
case"list":
PrintList();
break;
case"":
break;
default:
System.out.println("Sorry, I can not understand this command, enter \"help\" for help\n");
break;
}

}

}

public static void PrintList(){
int i=1;
System.out.print("---------------------------------------------\n");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Consider making this a constant to prevent repetition of the same code and will be more consistent when modification is made

System.out.println("Here are your current tasks in your list:");
for (String s :todolist ){
if(s == null){
continue;
}
System.out.printf("%d."+ GetIcon(i)+s+"\n",i);
i++;
}
System.out.print("---------------------------------------------\n");
}
static void ClearList(){
int i;
for (i=0;i<MAX_LIST_LENGTH;i++){

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
for (i=0;i<MAX_LIST_LENGTH;i++){
for (i = 0; i < MAX_LIST_LENGTH; i++) {

todolist[i]=null;
}
ListCount = 0;
}

static void ClearisDoneList(){
int i;
for (i=0;i<MAX_LIST_LENGTH;i++){
isDoneList[i]=false;
}
}

static String GetIcon(int i){
String s= isDoneList[i-1]?"x":" ";
return "["+s+"]";
}

static void SetDone(){
System.out.println("please type the task number you want to set as done \n");
PrintList();
int number= in.nextInt();

while(number>ListCount){
System.out.println("task do not exist, pleas enter a valid task number ");
number= in.nextInt();
}

isDoneList[number-1]=true;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
isDoneList[number-1]=true;
isDoneList[number-1] = true;

System.out.print("I've marked this task as done:");
System.out.printf(GetIcon(number)+todolist[number-1]+"\n");
}

static void SetUndone(){
System.out.println("please type the task number you want to set as not done \n");
PrintList();
int number= in.nextInt();

while(number>ListCount){
System.out.println("task do not exist, pleas enter a valid task number ");
number= in.nextInt();
}

isDoneList[number-1]=false;
System.out.print("I've marked this task as not done:");
System.out.printf(GetIcon(number)+todolist[number-1]+"\n");

}


}


62 changes: 62 additions & 0 deletions src/main/java/Qchat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import javax.swing.*;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Would it be better to not import all packages although according to google it is lightweight.

import java.util.Scanner;

public class Qchat {

static final String WELCOME_GREETING = new String(
"Qchat ,A truly humanized intelligent voice assisstant \n"
+"knows better about life and better about you\n"
+"What can I do for you?\n"
+"----------------------------------------------------------------\n") ;
static final String GOODBYE_GREETING = new String(
"--------------------------------------------------------\n" +
"goodbye\n"+ "Qchat, your life-long trusted companion\n");




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 may want to reduce the number of line breaks.

static String CommandReader(){

Scanner in = new Scanner(System.in);
String command ;
command = in.nextLine();

switch (command){
case "Bye":
System.out.print(GOODBYE_GREETING);
break;
case "list":
Todolist.HandleList();
break;


default:
echo(command);
break;

}
Comment on lines +24 to +26

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why is the other commands such as quit, help, mark, unmark etc. only accessible after the user input list?

return command;



}

private static void echo(String command) {
System.out.print("---------------------------------------------\n");
System.out.print(command +"\n");
System.out.print("---------------------------------------------\n");
Comment on lines +34 to +36

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 would suggest using System.lineSeparator() instead of "\n" for code compatibility with other systems.

}

public static void main(String[] args) {

System.out.print(WELCOME_GREETING);
String command = "" ;
while(!command.equals("Bye")){

command = CommandReader();

}

}

}
2 changes: 2 additions & 0 deletions src/main/java/Todo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
public class Todo {
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.