-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDictionary.java
More file actions
77 lines (77 loc) · 3.03 KB
/
Copy pathDictionary.java
File metadata and controls
77 lines (77 loc) · 3.03 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
//Nancy
import java.util.*;
public class Dictionary
{
public static void main (String [] args){
ArrayList<Word> words = new ArrayList();
Scanner scan = new Scanner (System.in);
System.out.println("Welcome to the dictionary");
int a = 9;
while (a !=6){
System.out.println("Menu:");
System.out.println("1: add a new word & definition");
System.out.println("2: remove a word & definition");
System.out.println("3: change a definition to a word");
System.out.println("4: get the definition of a word");
System.out.println("5: display all the words and the number of words");
System.out.println("6: quit");
a = scan.nextInt();
scan.nextLine();
if (a == 1){
System.out.println("What's the word?");
String w = scan.nextLine();
System.out.println("What's the definition?");
String d = scan.nextLine();
Word word1 = new Word (w, d);
words.add(word1);
}
else if (a == 2){
System.out.println("What's the word?");
String w = scan.nextLine();
boolean ans = false;
for (int i = 0; i < words.size(); i++){
if (words.get(i).getWord().equals (w)){
words.remove(i);
ans = true;
}
}
if (!ans){System.out.println("That's not in the dictionary");}
}
else if (a == 3){
System.out.println("What's the word?");
String w = scan.nextLine();
boolean ans = false;
for (int i = 0; i < words.size(); i++){
if (words.get(i).getWord().equals (w)){
System.out.println("What's the new definition?");
words.get(i).setDef(scan.nextLine());
ans = true;
}
}
if (!ans){System.out.println("That's not in the dictionary");}
}
else if (a == 4){
System.out.println("What's the word?");
String w = scan.nextLine();
boolean ans = false;
for (int i = 0; i < words.size(); i++){
if (words.get(i).getWord().equals (w)){
System.out.println(words.get(i).getDef());
ans = true;
}
}
if (!ans){System.out.println("That's not in the dictionary");}
}
else if (a == 5){
System.out.println("Words:");
for (int i = 0; i < words.size(); i++){
System.out.println(words.get(i).getWord());
}
System.out.println("There are " + words.size() + " words.");
}
else{
a = 6;
}
}
}
}