-
Notifications
You must be signed in to change notification settings - Fork 2
/
TextAnalyzer.java
46 lines (44 loc) · 967 Bytes
/
TextAnalyzer.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
package jl223vy_assign3;
public class TextAnalyzer {
private String text="";
public TextAnalyzer(String newT){
text=newT;
}
public int charCount(){
int count=0;
for(int i=0; i<text.length(); i++){
count++;
}
return count;
}
public int upperCaseCount(){
int countUC=0;
for(int i=0; i<text.length(); i++){
if(Character.isUpperCase(text.charAt(i)))
countUC++;
}
return countUC;
}
public int whitespaceCount(){
int countW=0;
for(int i=0; i<text.length(); i++){
if(Character.isWhitespace(text.charAt(i)))
countW++;
}
return countW;
}
public int digitCount(){
int countD=0;
for(int i=0; i<text.length(); i++){
if(Character.isDigit(text.charAt(i)))
countD++;
}
return countD;
}
public boolean containsChar(char ch){
return text.contains(Character.toString(ch));
}
public boolean containsString(String str){
return text.contains(str);
}
}