Skip to content
Open
Changes from 4 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
6169785
Level 0: adding greetLine and exitLine
wangsilangchange-hash Jan 27, 2023
d047c4e
Level 1: Adding echo function
wangsilangchange-hash Jan 27, 2023
b1f3481
Level 1,2: Rectify mistake in echo, where "bye" will also be echoed. …
wangsilangchange-hash Jan 27, 2023
e45b36b
Level 3: Complete level 3, add in printCurrentList function.
wangsilangchange-hash Jan 27, 2023
fbf03b0
Level 4 complete
wangsilangchange-hash Feb 3, 2023
9ac72cf
Level 5 complete
wangsilangchange-hash Feb 9, 2023
90cbc52
A-Packages
wangsilangchange-hash Feb 9, 2023
4eee682
Level 6 Complete
wangsilangchange-hash Feb 15, 2023
21815d8
Revert "Level 6 Complete"
wangsilangchange-hash Feb 15, 2023
21238c7
Revert "Revert "Level 6 Complete""
wangsilangchange-hash Feb 15, 2023
d5393f2
Fixing going back to master
wangsilangchange-hash Feb 17, 2023
55e06c9
Merge branch 'master' into branch-Level-6
wangsilangchange-hash Feb 17, 2023
d98e800
Level 7 complete
wangsilangchange-hash Feb 17, 2023
a9eebd0
A-Jar
wangsilangchange-hash Feb 17, 2023
7688011
A-MoreOOP
wangsilangchange-hash Mar 3, 2023
c240a47
Level-9, A-JavaDoc
wangsilangchange-hash Mar 3, 2023
fde76d5
Create user guide for Duke
JangusRoundstone Mar 3, 2023
da82fc2
Merge commit 'fde76d508d756f10c50396b0d6398fed4f2da62d' into branch-L…
wangsilangchange-hash Mar 3, 2023
d9e6240
Merge pull request #1 from JangusRoundstone/branch-Level-7
JangusRoundstone Mar 5, 2023
e202337
branch-Level-9
wangsilangchange-hash Mar 5, 2023
806f874
branch-A-JavaDoc
wangsilangchange-hash Mar 5, 2023
4b7e1b8
Merge pull request #2 from JangusRoundstone/branch-A-JavaDoc
JangusRoundstone Mar 5, 2023
d703de1
Merge tag 'branch-Level-9'
wangsilangchange-hash Mar 5, 2023
399c136
Published UG
wangsilangchange-hash Mar 5, 2023
d914533
Merge branch 'master' into branch-Level-9
wangsilangchange-hash Mar 5, 2023
b8552f4
Merge pull request #3 from JangusRoundstone/branch-Level-9
JangusRoundstone Mar 5, 2023
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
77 changes: 77 additions & 0 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import java.util.Arrays;
import java.util.Scanner;

public class Duke {
public static void main(String[] args) {
String logo = " ____ _ \n"
Expand All @@ -6,5 +9,79 @@ public static void main(String[] args) {
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
greetLine();
addList();
exitLine();
}
public static void greetLine(){
System.out.println("How may I be of service?");
}
public static void echo()
{
String line;
Scanner in = new Scanner(System.in);
line = in.nextLine();
while(!line.equals("bye")) {
System.out.println(line);
line = in.nextLine();
}
}

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'd want to indent the { } properly, like:
public static void echo(){

// your code
}

public static void exitLine(){
System.out.println("Glad I could be of help!");
}

public static void addList()
{

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Use K&R style brackets (as done in the exitLine method)

String[] list = new String[100];
String line;
Scanner in = new Scanner(System.in);
line = in.nextLine();
int numOfItems = 0;
while(!line.equals("bye")) {
if(line.equals("list")) { // users wants to know all text so far
printCurrentList(list, numOfItems);
}
else if(line.startsWith("mark")){
mark(line, list);
printCurrentList(list, numOfItems);
}
else if(line.startsWith("unmark")){
unmark(line,list);
printCurrentList(list, numOfItems);
}
else { // text from user
String item = (numOfItems + 1) + ".[ ] " + line; // convert to 1-based
list[numOfItems] = item;
++numOfItems;
}
line = in.nextLine(); // read in next line of text
}
}

public static void mark(String task, String[] list)
{
String locationOfTask = task.substring(5); // get the number of task to be marked
String taskToBeMarked = list[Integer.parseInt(locationOfTask) - 1];
String taskMarked = taskToBeMarked.replace("[ ]", "[X]");
list[Integer.parseInt(locationOfTask) - 1] = taskMarked;
System.out.println("Sir, your task has been marked as completed.");
}

public static void unmark(String task, String[] list)
{
String locationOfTask = task.substring(7);
String taskToBeUnmarked = list[Integer.parseInt(locationOfTask) - 1];
String taskUnmarked = taskToBeUnmarked.replace("[X]", "[ ]");
list[Integer.parseInt(locationOfTask) - 1] = taskUnmarked;
System.out.println("Sir, your task has been unmarked as requested.");
}

public static void printCurrentList(String[] list, int numOfItems)
{
String[] subList = Arrays.copyOf(list, numOfItems);
for(int i = 0; i < subList.length; ++i)
{
System.out.println(subList[i]);
}
}
}