-
Notifications
You must be signed in to change notification settings - Fork 0
/
DirectCompare.java
98 lines (89 loc) · 2.65 KB
/
DirectCompare.java
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
//No spaces at end or beginning. No double or + spaces.
import java.util.ArrayList;
public class DirectCompare
{
private String txt1;
private String txt2;
public DirectCompare(String s1, String s2)
{
txt1 = s1;
txt2 = s2;
}
public void compare()
{
ArrayList<String> words1 = new ArrayList<String>();
ArrayList<String> words2 = new ArrayList<String>();
int start = 0;
boolean isEqual = true;
double total = 0.0;
System.out.println(txt1.length());
for(int x = 0; x<txt1.length()-1; x++)
{
System.out.println(txt1.length()-2);
System.out.println(x==txt1.length()-2);
System.out.println(x);
if(txt1.substring(x, x+1).compareTo(" ")==0)
{
words1.add(txt1.substring(start, x));
System.out.println(txt1.substring(start, x));
start = x+1;
}
else if (x==txt1.length()-2 && txt1.substring(x, x+1).compareTo(" ")!=0)
{
words1.add(txt1.substring(start, x+2));
System.out.println(txt1.substring(start, x));
start = x+1;
}
}
start = 0;
for(int x = 0; x<txt2.length()-1; x++)
{
if(txt2.substring(x, x+1).compareTo(" ")==0)
{
words2.add(txt2.substring(start, x));
start = x+1;
}
else if (x==txt2.length()-2 && txt2.substring(x, x+1).compareTo(" ")!=0)
{
words2.add(txt2.substring(start, x+2));
start = x+1;
}
}
int num = 0;
if(words1.size()>words2.size())
{
for(String str : words2)
{
System.out.println(str);
if(str.compareTo(words1.get(num))==0)
{
total++;
}
else
{
isEqual = false;
}
num++;
}
}
else
{
for(String str : words1)
{
System.out.println(words2.get(num));
System.out.println(str);
if(str.compareTo(words2.get(num))==0)
{
total++;
}
else
{
isEqual = false;
}
num++;
}
}
System.out.println("Percentage: " + total/num);
System.out.println("Equal?: " + isEqual);
}
}