-
Notifications
You must be signed in to change notification settings - Fork 76
[karishma-t] iP #84
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
base: master
Are you sure you want to change the base?
[karishma-t] iP #84
Changes from 5 commits
d411f2a
758863c
3115910
d97f8cf
4a96d47
2b5ef00
3edf721
98652d7
eb53e6c
92d18e3
a362da3
9063cb1
846da7b
199eacc
dbb8e86
6c3d74d
2d3ddff
ec4f1a2
d74c4c6
3ae016a
0ddd375
fa5d740
1b9e891
ac6605a
51df475
2b9826e
c9f2dc5
3313f0d
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 @@ | ||
| Pull request 1 |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
|
|
||
| import java.util.Scanner; | ||
|
|
||
| public class Ken { | ||
| public static void main(String[] args) { | ||
| Scanner scanner = new Scanner(System.in); | ||
|
|
||
| //Initialise array to store tasks | ||
| String[] tasks = new String[100]; | ||
| boolean[] taskStatus = new boolean[100]; // true for done, false for not done | ||
| int taskCount = 0; | ||
|
|
||
| // Print the initial message | ||
| System.out.println(" ____________________________________________________________"); | ||
| System.out.println(" Hello! I'm Ken"); | ||
| System.out.println(" What dyu want?"); | ||
| System.out.println("____________________________________________________________"); | ||
|
|
||
| // Read and echo user commands until "bye" is entered | ||
| while (true) { | ||
| String userInput = scanner.nextLine(); | ||
|
|
||
| // Echo the user's command | ||
| System.out.println(" ____________________________________________________________"); | ||
|
|
||
|
|
||
| // Check if the user wants to exit | ||
|
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. Good job on leaving comments with same indentation |
||
| if (userInput.equalsIgnoreCase("bye")) { | ||
| System.out.println("____________________________________________________________"); | ||
| System.out.println(" Bye then!"); | ||
| System.out.println("____________________________________________________________"); | ||
| break; // Exit the loop | ||
| } else if (userInput.equalsIgnoreCase("list")) { | ||
| System.out.println(" Tasks "); | ||
| for (int i = 0; i < taskCount; i++) { | ||
| char statusSymbol = taskStatus[i] ? 'X' : ' '; | ||
| System.out.println(" " + (i + 1) + ".[" + statusSymbol + "] " + tasks[i]); } | ||
| } else if (userInput.startsWith("mark " )) { | ||
| try { | ||
| int taskIndex = Integer.parseInt(userInput.substring(5).trim()) - 1; | ||
| if (taskIndex >= 0 && taskIndex < taskCount) { | ||
|
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 you can break the code up into different functions for better readability |
||
| taskStatus[taskIndex] = true; | ||
| System.out.println(" Nice! I've marked this task as done:"); | ||
| System.out.println(" [X] " + tasks[taskIndex]); | ||
| } else { | ||
| System.out.println(" Task not found. Please provide a valid task number."); | ||
| } | ||
| } catch (NumberFormatException e) { | ||
| System.out.println(" Invalid input. Please provide a valid task number."); | ||
| } | ||
| } else if (userInput.startsWith("unmark ")) { | ||
| try { | ||
| int taskIndex = Integer.parseInt(userInput.substring(7).trim()) - 1; | ||
| if (taskIndex >= 0 && taskIndex < taskCount) { | ||
| taskStatus[taskIndex] = false; | ||
| System.out.println(" OK, I've marked this task as not done yet:"); | ||
| System.out.println(" [ ] " + tasks[taskIndex]); | ||
| } else { | ||
| System.out.println(" Task not found. Please provide a valid task number."); | ||
| } | ||
|
Comment on lines
+52
to
+62
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 you can add some comments to make it easier to read and understand :) |
||
| } catch (NumberFormatException e) { | ||
|
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. Good job on format of try-catch statements |
||
| System.out.println(" Invalid input. Please provide a valid task number."); | ||
| } | ||
| } | ||
| else { | ||
|
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. Should this else be on the previous line? eg: } else { |
||
| //Add task to the array | ||
| tasks[taskCount] = userInput; | ||
| taskCount++; | ||
| System.out.println(" added: " + userInput); | ||
| } | ||
| } | ||
| // Close the scanner when done | ||
| scanner.close(); | ||
| } | ||
| } | ||
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.
Should this variable name sound more like a boolean? for example: isDone