-
Notifications
You must be signed in to change notification settings - Fork 434
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
Zhou Yang ip #469
base: master
Are you sure you want to change the base?
Zhou Yang ip #469
Changes from 6 commits
55f9f9f
f837ddb
a6f7324
6a2c3c4
230d629
0e99f6d
3edd219
ed31075
c9bb7d8
7371a61
b7a9572
cc18fdb
326db9d
c87e0cb
0c8e8da
c575fa3
a88f458
43d9349
a31ec41
dc2bf14
5211ea8
ecabd86
c4064ae
d16e0b4
9985e16
18e9e33
f094fc6
f2fcffc
348cb2e
285b828
abc1856
ce12d48
14d3723
2ddea92
efa4525
242c7d6
3625a37
46ae3ea
1a84a6b
98b1583
87066e5
e3ca239
38ad3a1
4a08237
7389801
8631107
4979698
3d8edb8
90b394b
48ad843
f0295e5
3c917f4
fdf5b56
e777fa8
d72ebf8
91d9fff
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,7 @@ | ||
public class Duke_Level0 { | ||
public static void main(String[] args) { | ||
System.out.println("Hello, I'm SamuelBot"); | ||
System.out.println("What can I do for you?"); | ||
System.out.println("Bye. Hope to see you again soon!"); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import java.util.Scanner; | ||
public class Duke_Level1 { | ||
public static void main(String[] args) { | ||
System.out.println("Hello! I'm SamuelBot"); | ||
System.out.println("What can I do for you?"); | ||
Scanner s = new Scanner(System.in); | ||
String str = s.nextLine(); | ||
while(! str.equals("bye")) { | ||
System.out.println(str); | ||
str = s.nextLine(); | ||
} | ||
System.out.println("Bye. Hope to see you again soon!"); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Scanner; | ||
|
||
public class Duke_Level2 { | ||
public static void main(String[] args) { | ||
List<String> list = new ArrayList<>(); | ||
System.out.println("Hello! I'm SamuelBot"); | ||
System.out.println("What can I do for you?"); | ||
Scanner s = new Scanner(System.in); | ||
String str = s.nextLine(); | ||
while(! str.equals("bye")) { | ||
if(str.equals("list")){ | ||
for(int i = 0; i < list.size(); i++){ | ||
System.out.println((i+1) + ". " + list.get(i)); | ||
} | ||
} | ||
else { | ||
list.add(str); | ||
System.out.println("added: " + str); | ||
} | ||
str = s.nextLine(); | ||
} | ||
System.out.println("Bye. Hope to see you again soon!"); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Scanner; | ||
public class Duke_Level3 { | ||
public static void main(String[] args) { | ||
List<String> list = new ArrayList<>(); | ||
list.add("read book"); | ||
list.add("return book"); | ||
list.add("buy bread"); | ||
Scanner s = new Scanner(System.in); | ||
String str = s.nextLine(); | ||
String[] done = new String[100]; | ||
while(true){ | ||
if(str.equals("list")){ | ||
System.out.println("Here are the tasks in your list:"); | ||
for(int i = 1; i <= list.size(); i++){ | ||
System.out.println(done[i] + list.get(i - 1)); | ||
} | ||
} | ||
else{ | ||
if(str.substring(0, 4).equals("mark")){ | ||
int temp = Integer.parseInt(str.substring(5)); | ||
done[temp] = "[X] "; | ||
System.out.println("Nice! I've marked this task as done: "); | ||
System.out.println(done[temp] + list.get(temp - 1)); | ||
} | ||
else{ | ||
int temp = Integer.parseInt(str.substring(7)); | ||
done[temp] = "[] "; | ||
System.out.println("OK, I've marked this task as not done yet:"); | ||
System.out.println(done[temp] + list.get(temp - 1)); | ||
} | ||
} | ||
str = s.nextLine(); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,85 @@ | ||||||
import java.util.ArrayList; | ||||||
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 consider having a package for |
||||||
import java.util.List; | ||||||
import java.util.Scanner; | ||||||
public class Duke_Level4 { | ||||||
public static void main(String[] args) { | ||||||
String logo = " ____ _ \n" | ||||||
+ "| _ \\ _ _| | _____ \n" | ||||||
+ "| | | | | | | |/ / _ \\\n" | ||||||
+ "| |_| | |_| | < __/\n" | ||||||
+ "|____/ \\__,_|_|\\_\\___|\n"; | ||||||
System.out.println("Hello from\n" + logo); | ||||||
System.out.println("What can I do for you?"); | ||||||
List<String> list = new ArrayList<>(); | ||||||
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. Could this variable name be updated to show that there are multiple objects represented?
Suggested change
|
||||||
String[] task = new String[100]; | ||||||
for (int i = 0; i < task.length; i++) { | ||||||
task[i] = "[]"; | ||||||
} | ||||||
String[] done = new String[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. Maybe this variable can use a better name such as |
||||||
for (int i = 0; i < done.length; i++) { | ||||||
done[i] = "[] "; | ||||||
} | ||||||
Scanner s = new Scanner(System.in); | ||||||
String str = s.nextLine(); | ||||||
while(! str.equals("bye")){ | ||||||
if(str.substring(0, 4).equals("mark")){ | ||||||
Comment on lines
+24
to
+25
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. I think there should be a space in between |
||||||
int temp = Integer.parseInt(str.substring(5)); | ||||||
done[temp] = "[X] "; | ||||||
System.out.println("Nice! I've marked this task as done: "); | ||||||
System.out.println(task[temp] + done[temp] + list.get(temp - 1)); | ||||||
} | ||||||
else if(str.equals("list")){ | ||||||
System.out.println("Here are the tasks in your list:"); | ||||||
for (int i = 0; i < list.size(); i++) { | ||||||
System.out.println((i + 1) + ". " + task[i] + done[i] + list.get(i)); | ||||||
} | ||||||
} | ||||||
else if (str.startsWith("todo")) { | ||||||
list.add(str.substring(5)); | ||||||
int lastIndex = list.size() - 1; | ||||||
if (lastIndex >= 0) { | ||||||
task[lastIndex] = "[T]"; | ||||||
done[lastIndex] = "[] "; | ||||||
System.out.println("Got it. I've added this task:"); | ||||||
System.out.println(task[lastIndex] + done[lastIndex] + list.get(lastIndex)); | ||||||
} else { | ||||||
System.out.println("Got it. I've added this task:"); | ||||||
System.out.println("[T][] " + list.get(0)); | ||||||
} | ||||||
System.out.println("Now you have " + list.size() + " tasks in the list."); | ||||||
} | ||||||
else if(str.startsWith("event")) { | ||||||
String[] splits = str.split("/from"); | ||||||
task[list.size()] = "[E]"; | ||||||
done[list.size()] = "[] "; | ||||||
int idxfrom = str.indexOf("/from"); | ||||||
int idxto = str.indexOf("/to"); | ||||||
String from = str.substring(idxfrom + 6, idxto); | ||||||
String to = str.substring(idxto + 4); | ||||||
String temp = "(from: " + from + "to: " + to + ")"; | ||||||
list.add(splits[0] + temp); | ||||||
System.out.println("Got it. I've added this task:"); | ||||||
System.out.println(task[list.size() - 1] + done[list.size() - 1] + list.get(list.size() - 1)); | ||||||
System.out.println("Now you have " + list.size() + " tasks in the list."); | ||||||
} | ||||||
else if(str.startsWith("unmark")) { | ||||||
int temp = Integer.parseInt(str.substring(7)); | ||||||
done[temp] = "[] "; | ||||||
System.out.println("OK, I've marked this task as not done yet:"); | ||||||
System.out.println(task[temp] + done[temp] + list.get(temp - 1)); | ||||||
} | ||||||
else if(str.startsWith("deadline")){ | ||||||
task[list.size()] = "[D]"; | ||||||
done[list.size()] = "[] "; | ||||||
String temp = " (by: " + str.split("/by")[1].trim() + ")"; | ||||||
list.add(str.substring(8).split("/by")[0].trim() + temp); | ||||||
System.out.println("Got it. I've added this task:"); | ||||||
System.out.println(task[list.size() - 1] + done[list.size() - 1] + list.get(list.size() - 1)); | ||||||
System.out.println("Now you have " + list.size() + " tasks in the list."); | ||||||
} | ||||||
str = s.nextLine(); | ||||||
} | ||||||
System.out.println("Bye. Hope to see you again soon!"); | ||||||
} | ||||||
} | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
package PACKAGE_NAME;public class Duke_Level5 { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
package PACKAGE_NAME;public class EventTask { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
package PACKAGE_NAME;public class Task { | ||
} |
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.
I think there should not be a space between
!
andstr.equals("bye")
?