-
Notifications
You must be signed in to change notification settings - Fork 16
Zahra Al Eid - Selection Project #1
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?
Changes from all commits
94207c6
3813c82
ed2dcf0
dd36eea
134d820
492845d
24f150f
ebb0044
bddc169
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,3 @@ | ||
| { | ||
| "CurrentProjectSetting": null | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "ExpandedNodes": [ | ||
| "", | ||
| "\\src", | ||
| "\\src\\core", | ||
| "\\src\\models" | ||
| ], | ||
| "SelectedNode": "\\src\\core\\note_app.dart", | ||
| "PreviewInSolutionExplorer": false | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| { | ||
| // Use IntelliSense to learn about possible attributes. | ||
| // Hover to view descriptions of existing attributes. | ||
| // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
| "version": "0.2.0", | ||
| "configurations": [ | ||
| { | ||
| "name": "Dart & Flutter", | ||
| "request": "launch", | ||
| "type": "dart" | ||
| } | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| import 'note_app.dart'; | ||
| class Note { | ||
|
|
||
| String? Title, Content; | ||
|
Contributor
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. consider using non-nullable types for your class properties if possible. This can help catch potential null-related errors during development. String title; Note.create({required this.title, required this.content}); |
||
|
|
||
|
|
||
|
|
||
| Note(String? title, String? content){ | ||
| this.Title= title; | ||
| this.Content=content; | ||
| } | ||
|
|
||
|
|
||
| void setTtile(String? Title){ | ||
| this.Title=Title; | ||
| } | ||
|
|
||
| void setContent(String? Content){ | ||
| this.Content=Content; | ||
| } | ||
|
|
||
| String? getTitle(){ | ||
| return Title; | ||
| } | ||
|
|
||
| String? getContent(){ | ||
| return Content; | ||
| } | ||
|
|
||
| static List<Note> NotesList =[]; | ||
|
Contributor
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. uses camelCase |
||
|
|
||
| static void CreateNote(Note newNote){ | ||
|
|
||
| NotesList.add(newNote); | ||
| print("Note added sucessfuly"); | ||
|
|
||
| } | ||
|
|
||
| static void deleteNoteM(String? delNoteV){ | ||
| bool found=false; | ||
| for (int i =0; i<NotesList.length ;i++){ | ||
|
|
||
| if (NotesList[i].Title== delNoteV){ | ||
| found =true; | ||
| NotesList.removeAt(i); | ||
| print("note was deleted sucessfully"); | ||
| break; | ||
| } | ||
|
|
||
| } | ||
| if(!found){ | ||
| print("note wasn't found"); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| static void editTitleM(String? toEdit ,String? editNoteV){ | ||
|
Contributor
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. The methods editTitleM and editContentM have similar logic. You could consider refactoring the common logic into a method to avoid code duplication. |
||
|
|
||
| bool found=false; | ||
| for (int i =0; i<NotesList.length ;i++){ | ||
| if (NotesList[i].Title== toEdit){ | ||
| found =true; | ||
| NotesList[i].setTtile(editNoteV); | ||
| print("note was edited sucessfully"); | ||
| break; | ||
| } | ||
|
|
||
| } | ||
| if(!found){ | ||
| print("note wasn't found"); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| static void editContentM(String? toEdit ,String? editNoteV){ | ||
|
|
||
| bool found=false; | ||
| for (int i =0; i<NotesList.length ;i++){ | ||
| if (NotesList[i].Title== toEdit){ | ||
| found =true; | ||
| NotesList[i].setContent(editNoteV); | ||
| print("note was edited sucessfully"); | ||
| break; | ||
| } | ||
|
|
||
| } | ||
| if(!found){ | ||
| print("note wasn't found"); | ||
| } | ||
| } | ||
|
|
||
| static void searchByTitleM(String? title){ | ||
| bool found=false; | ||
| for (int i =0; i<NotesList.length ;i++){ | ||
| if (NotesList[i].Title== title){ | ||
| found =true; | ||
| print("Note is found! \n =============== \n Content: \n ==============="); | ||
| print(NotesList[i].Content); | ||
| break; | ||
| } | ||
|
|
||
| } | ||
| if(!found){ | ||
| print("note wasn't found"); | ||
| } | ||
| } | ||
|
|
||
| static void searchByContentM(String? content){ | ||
| bool found=false; | ||
| for (int i =0; i<NotesList.length ;i++){ | ||
| if (NotesList[i].Content== content){ | ||
| found =true; | ||
| print("Note is found! \n ============ \n Title: "); | ||
| print(NotesList[i].Title); | ||
| break; | ||
| } | ||
|
|
||
| } | ||
| if(!found){ | ||
| print("note wasn't found"); | ||
| } | ||
| } | ||
|
|
||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,127 @@ | ||
| import 'dart:io'; | ||
| import 'Note.dart'; | ||
| String? delNoteV, editNoteV, toEdit; | ||
|
|
||
| class NoteApp { | ||
| // TODO: Complete the run function | ||
|
|
||
| void run() { | ||
|
Contributor
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. Consider separating different functionalities into separate methods. if (operation > 0 && operation < 7) {
switch (operation) {
case 1:
createNote();
break;
case 2:
editNote();
break;
case 3:
deleteNote();
break;
case 4:
printNotes();
break;
case 5:
searchNote();
break;
case 6:
print("Exiting Note Taking App.");
break;
default:
print("Invalid choice. Please enter a number between 1 to 6.");
break;
}
} else {
print("Invalid choice. Please enter a number between 1 to 6.");
}
} while (operation != 6);
|
||
| print('Hello, world!'); | ||
|
|
||
|
|
||
| int operation ; | ||
| do { | ||
| print(" \nNOTE TAKING APP \n \n ***************** \n 1- Create a note \n 2- Edit a note \n 3- Delete a note \n 4- Print notes \n 5- Search for a note \n 6- Exit \n ***************** \n "); | ||
|
|
||
| print ("Choose an operation "); | ||
| operation = int.parse(stdin.readLineSync()!); | ||
| if (operation>0 && operation <7){ | ||
| switch (operation) { | ||
|
|
||
| case 1: | ||
| //create a note | ||
| try{ | ||
| String? newNoteTitle; | ||
| String? newNoteContent; | ||
|
|
||
| print("Title: \n ****"); | ||
| newNoteTitle = stdin.readLineSync(); | ||
|
Contributor
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. check if the title already exists before adding the note or if the title is empty. |
||
|
|
||
| print ("content: \n ****"); | ||
| newNoteContent = stdin.readLineSync(); | ||
|
|
||
| Note newNote= Note(newNoteTitle,newNoteContent); | ||
| Note.CreateNote(newNote); | ||
| break;} catch (e){ | ||
| print ("invalid input"); | ||
| } | ||
| case 2: { | ||
| //Edit a note's title or content | ||
|
|
||
| print("To edit the title press (1), Content press (2)"); | ||
| try { | ||
| int editSwitch= int.parse(stdin.readLineSync()!); | ||
| switch (editSwitch) { | ||
| case 1 : print ("Enter the title of the note to edit: ") ; | ||
| toEdit=stdin.readLineSync(); | ||
| print ("enter the new title: "); | ||
| editNoteV= stdin.readLineSync(); | ||
| Note.editTitleM(toEdit,editNoteV); | ||
| break; | ||
|
|
||
| case 2: | ||
| print ("Enter the title of the note to edit: ") ; | ||
| toEdit=stdin.readLineSync(); | ||
| print ("enter the new Cotent: "); | ||
| editNoteV= stdin.readLineSync(); | ||
| Note.editContentM(toEdit,editNoteV); | ||
| break; | ||
|
|
||
| default: | ||
| print ("invalid input"); | ||
| }} catch(e){ | ||
| print ("invalid input"); | ||
| }} | ||
| break; | ||
|
|
||
| case 3: | ||
| //Delete a note | ||
| try{ | ||
| print("Write the title of the note to delete: "); | ||
| delNoteV= stdin.readLineSync(); | ||
| Note.deleteNoteM(delNoteV); | ||
| break; | ||
| } catch (e){ | ||
| print ("invalid input"); | ||
| } | ||
| case 4: | ||
| // print all notes | ||
| try{ | ||
| print("\n All Notes:"); | ||
| print(" _______________________ "); | ||
|
|
||
| for (var i = 0; i < Note.NotesList.length; i++) { | ||
| print(" | |"); | ||
| print(" | Title: ${Note.NotesList[i].Title}"); | ||
| print(" | Content: ${Note.NotesList[i].Content} "); | ||
| print(" | | "); | ||
| print(" |______________________| "); | ||
| } | ||
| break;} | ||
| catch (e){ | ||
| print ("invalid input"); | ||
| } | ||
| case 5: | ||
| //searsh BY titile OR content | ||
|
|
||
| print("To search by title press (1) and to search by Content press (2)"); | ||
| try { | ||
| int searchSwitch= int.parse(stdin.readLineSync()!); | ||
| switch (searchSwitch) { | ||
| case 1 : | ||
| print ("Enter the title of the note: ") ; | ||
| toEdit=stdin.readLineSync(); | ||
| Note.searchByTitleM(toEdit); | ||
| break; | ||
|
|
||
| case 2: | ||
| print ("Enter the content of the note: ") ; | ||
| toEdit=stdin.readLineSync(); | ||
| Note.searchByContentM(toEdit); | ||
| break; | ||
|
|
||
| default: | ||
| print("Invalid choice"); | ||
|
|
||
| }} catch(e){ | ||
| print ("invalid input"); | ||
| } | ||
| break; | ||
|
|
||
|
|
||
| default: | ||
| exit; | ||
|
Contributor
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 break to exit the loop and let the loop condition handle the exit. |
||
|
|
||
| }} | ||
| } while ( operation!=6); | ||
|
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,14 @@ | ||
| import 'core/note_app.dart'; | ||
|
|
||
|
|
||
|
|
||
|
|
||
| void main(List<String> args) { | ||
|
|
||
|
|
||
|
|
||
| NoteApp().run(); | ||
|
|
||
|
|
||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,14 @@ | ||
| //TODO: Define a note model class | ||
| class NoteModel {} | ||
| class NoteModel { | ||
| String? name; | ||
| String? content; | ||
|
|
||
|
|
||
| NoteModel({this.name, this.content}); | ||
|
|
||
| String? Create (String name , String content){ | ||
|
|
||
| return name+content; | ||
| } | ||
|
|
||
| } |
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.
Consider separating the note title and content into the note_model.dart file, and place note functions in a NoteManager class for better readability.