-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWord.java
More file actions
43 lines (35 loc) · 1.04 KB
/
Word.java
File metadata and controls
43 lines (35 loc) · 1.04 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
import java.util.ArrayList;
import java.util.Scanner;
import java.util.Arrays;
import static java.lang.System.*;
public class Word implements Comparable<Word>
{
private String word;
public Word( String s)
{
word = s;
}
public int compareTo(Word other) {
int vowela=0;
int vowelb=0;
for(int i=0; i<word.length(); i++) {
if(word.charAt(i)=='a'||word.charAt(i)=='e'||word.charAt(i)=='o'||word.charAt(i)=='i'||word.charAt(i)=='u') {
vowela++;
}
}
for(int i=0;i<other.word.length(); i++) {
if(other.word.charAt(i)=='a'||other.word.charAt(i)=='e'||other.word.charAt(i)=='o'||other.word.charAt(i)=='i'||other.word.charAt(i)=='u') {
vowelb++;
}
}
if(vowela!=vowelb) {
return vowela-vowelb;
}
else {
return word.compareTo(other.word);
}
}
public String toString() {
return word;
}
}