-
Notifications
You must be signed in to change notification settings - Fork 200
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
[Wang Silang] iP #214
Open
JangusRoundstone
wants to merge
26
commits into
nus-cs2113-AY2223S2:master
Choose a base branch
from
JangusRoundstone:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[Wang Silang] iP #214
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
d047c4e
Level 1: Adding echo function
b1f3481
Level 1,2: Rectify mistake in echo, where "bye" will also be echoed. …
e45b36b
Level 3: Complete level 3, add in printCurrentList function.
fbf03b0
Level 4 complete
9ac72cf
Level 5 complete
90cbc52
A-Packages
4eee682
Level 6 Complete
21815d8
Revert "Level 6 Complete"
21238c7
Revert "Revert "Level 6 Complete""
d5393f2
Fixing going back to master
55e06c9
Merge branch 'master' into branch-Level-6
d98e800
Level 7 complete
a9eebd0
A-Jar
7688011
A-MoreOOP
c240a47
Level-9, A-JavaDoc
fde76d5
Create user guide for Duke
JangusRoundstone da82fc2
Merge commit 'fde76d508d756f10c50396b0d6398fed4f2da62d' into branch-L…
d9e6240
Merge pull request #1 from JangusRoundstone/branch-Level-7
JangusRoundstone e202337
branch-Level-9
806f874
branch-A-JavaDoc
4b7e1b8
Merge pull request #2 from JangusRoundstone/branch-A-JavaDoc
JangusRoundstone d703de1
Merge tag 'branch-Level-9'
399c136
Published UG
d914533
Merge branch 'master' into branch-Level-9
b8552f4
Merge pull request #3 from JangusRoundstone/branch-Level-9
JangusRoundstone File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
|
@@ -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(); | ||
} | ||
} | ||
public static void exitLine(){ | ||
System.out.println("Glad I could be of help!"); | ||
} | ||
|
||
public static void addList() | ||
{ | ||
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. 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]); | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
You'd want to indent the { } properly, like:
public static void echo(){
// your code
}