-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprob10.java
More file actions
98 lines (86 loc) · 3.13 KB
/
Copy pathprob10.java
File metadata and controls
98 lines (86 loc) · 3.13 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
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
public class prob10 {
public static void main(String[] args) throws FileNotFoundException {
/**
* Story sentence
* NOUNS
* noun
* ADVERBS
* adverb
* VERBS
* verb
* ADJECTIVES
* adjective
* END
*
* [N] = nouns [AV] = adverbs [V] = verbs [AJ] = adjectives
*/
ArrayList<String> nouns = new ArrayList<String>();
ArrayList<String> adverbs = new ArrayList<String>();
ArrayList<String> verbs = new ArrayList<String>();
ArrayList<String> adjectives = new ArrayList<String>();
Scanner in = new Scanner(new File("input.txt"));
String StorySentence = in.nextLine();
String StorySentenceTemp = StorySentence;
String temp = in.nextLine();
while(!temp.equals("ADVERBS")) {
temp = in.nextLine();
if(!temp.equals("ADVERBS"))
nouns.add(temp);
}
while(!temp.equals("VERBS")) {
temp = in.nextLine();
if(!temp.equals("VERBS"))
adverbs.add(temp);
}
while(!temp.equals("ADJECTIVES")) {
temp = in.nextLine();
if(!temp.equals("ADJECTIVES"))
verbs.add(temp);
}
while(!temp.equals("END")) {
temp = in.nextLine();
if(!temp.equals("END"))
adjectives.add(temp);
}
while(StorySentence.contains("[N]")) {
StorySentence = StorySentence.replaceFirst("\\[N\\]", nouns.get(0));
nouns.remove(0);
}
while(StorySentence.contains("[AV]")) {
StorySentence = StorySentence.replaceFirst("\\[AV\\]", adverbs.get(0));
adverbs.remove(0);
}
while(StorySentence.contains("[V]")) {
StorySentence = StorySentence.replaceFirst("\\[V\\]", verbs.get(0));
verbs.remove(0);
}
while(StorySentence.contains("[AJ]")) {
StorySentence = StorySentence.replaceFirst("\\[AJ\\]", adjectives.get(0));
adjectives.remove(0);
}
System.out.println(StorySentence);
//sentence 2
StorySentence = StorySentenceTemp;
while(StorySentence.contains("[N]")) {
StorySentence = StorySentence.replaceFirst("\\[N\\]", nouns.get(0));
nouns.remove(0);
}
while(StorySentence.contains("[AV]")) {
StorySentence = StorySentence.replaceFirst("\\[AV\\]", adverbs.get(0));
adverbs.remove(0);
}
while(StorySentence.contains("[V]")) {
StorySentence = StorySentence.replaceFirst("\\[V\\]", verbs.get(0));
verbs.remove(0);
}
while(StorySentence.contains("[AJ]")) {
StorySentence = StorySentence.replaceFirst("\\[AJ\\]", adjectives.get(0));
adjectives.remove(0);
}
System.out.println(StorySentence);
}
}