-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNotebook.java
More file actions
106 lines (94 loc) · 2.96 KB
/
Notebook.java
File metadata and controls
106 lines (94 loc) · 2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import java.util.ArrayList;
import java.util.Scanner;
//Unit 1 - task 06
/**
* @author Olya Lee
* @since 0.1.1
*/
public class Notebook {
ArrayList<Note> notes;
Notebook(){
notes = new ArrayList<Note>();
System.out.println("The notebook was created.");
}
/**
* @return a size of the ArrayList notes
*/
public int getSize(){
if(notes.size()>0)
{return notes.size();}
else return 0;
}
/**
* Allows to add a new note to the Notebook.
* @return true - if the note was successfully added, otherwise false.
*/
public boolean addNote(){
Scanner sc = new Scanner(System.in);
System.out.println("You can create a new note now:");
Note n = new Note();
n.setS(sc.nextLine());
if(notes.add(n)){
System.out.println("Your note was successfully added.");
return true;}
else return false;
}
/**
* Allows to remove the note from Notebook. Gives an opportunity to the user to choose to remove the note by typing "yes" in a console.
* @param i - the index of the note which should be removed.
* @return true - if the note was successfully removed, otherwise false.
*/
public boolean removeNote(int i){
System.out.println("Are you sure you want to delete the note below?");
System.out.println(notes.get(i).getS());
System.out.println("Please type 'yes' if you do:");
Scanner sc = new Scanner(System.in);
String answer = sc.nextLine();
if(answer.equalsIgnoreCase("yes"))
{
notes.remove(i);
return true;
}
else return false;
}
/**
* Allows to edit the note from Notebook by rewriting something new instead. Gives an opportunity to the user to choose to edit the note by typing "yes" in a console.
* @param i - the index of the not which should be edited.
* @return true - if the note was successfully edited, otherwise false.
*/
public boolean editNote(int i){
System.out.println("Do you want to edit the note below?");
System.out.println(notes.get(i).getS());
System.out.println("Please type 'yes' if you do:");
Scanner sc = new Scanner(System.in);
String answer = sc.nextLine();
if(answer.equalsIgnoreCase("yes"))
{
System.out.println("Go ahead:");
notes.get(i).setS(sc.nextLine());
return true;
}
else return false;
}
/**
* Allows to see notes from notebook all at once
*/
public void showAllNotes(){
System.out.println("The notebook currently have following notes:");
for(Note n: notes) {
System.out.println(n.getS());
}
}
}
/**
* Class was designed for usage in Notebook and allows to write one note.
*/
class Note {
private String s= "";
void setS(String s){
this.s = s;
}
String getS(){
return s;
}
}