Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
10 changes: 0 additions & 10 deletions src/main/java/Duke.java

This file was deleted.

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();

}

}

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

public class Todolist {
private static final int MAX_LIST_LENGTH = 100;
static String[] todolist = new String[MAX_LIST_LENGTH];
static boolean[] isDoneList = new boolean[MAX_LIST_LENGTH];

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 a static final int, instead of specifying "100" directly in the array as you have avoided using magic numbers.


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

public static void AddToList(){
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":
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();
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");
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);

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 add spaced before and after the "+", this is part of coding standards.

i++;
}
System.out.print("---------------------------------------------\n");
}
static void ClearList(){
int 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;
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");

}


}