-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNotebook.java
More file actions
115 lines (100 loc) · 2.23 KB
/
Notebook.java
File metadata and controls
115 lines (100 loc) · 2.23 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
107
108
109
110
111
112
113
114
115
package ArrayList;
//ArrayList long list of methods
import java.util.ArrayList;
import java.util.Iterator;
/**
* A class to maintain an arbitrarily long list of notes.
* Notes are numbered for external reference by a human user.
* In this version, note numbers start at 0.
*
* @author David J. Barnes and Michael Kolling.
* @version 2008.03.30
*/
public class Notebook {
// Storage for an arbitrary number of notes.
private ArrayList<String> notes;
/**
* Perform any initialization that is required for the
* notebook.
*/
public Notebook() {
notes = new ArrayList<String>();
}
/**
* Store a new note into the notebook.
*/
public void storeNote(String note) {
notes.add(note);
}
/**
* @return The number of notes currently in the notebook.
*/
public int numberOfNotes() {
return notes.size();
}
/**
* Show a note.
* @param noteNumber The number of the note to be shown.
*/
public void showNote(int noteNumber)
{
if(noteNumber < 0) {
System.out.println("invalid index given");
}
else if(noteNumber < numberOfNotes()) {
System.out.println(notes.get(noteNumber));
}
else {
System.out.println("there are fewer items in the notebook than that");
}
}
public void removeNote(int noteNumber)
{
if(noteNumber < 0) {
System.out.println("invalid index given");
}
else if(noteNumber < numberOfNotes()) {
notes.remove(noteNumber);
}
else {
System.out.println("there are fewer items in the notebook than that");
}
}
public void multiplesOfFive()
{
int i = 10;
while(i < 100)
{
System.out.println(i);
i = i + 5;
}
}
public int sum(int a, int b)
{
int index = a;
int result = 0;
while(index <= b)
{
result = result + index;
index = index + 1;
}
return result;
}
public int product(int a, int b) {
int index = a;
int result = 1;
while(index <= b) {
result = result * index;
index = index + 1;
}
return result;
}
public boolean isPrime (int n) {
if (n<=1)return false;
if (n==2) return true;
for (int i = 2;i<=n-1;i++) {
if (n%i==0)return false;
}
return true;
}
}