This is an Intro to JAVA Course I am stuck below on finishing the public int get
ID: 3733094 • Letter: T
Question
This is an Intro to JAVA Course
I am stuck below on finishing the public int getECount() & public String initials() please see below instructions. Code I have is below and help would be appreciated thank you!
private String text;
public LoopyText(String theText)
{
text = theText;
}
public String getText()
{
return text;
}
public String getUpperCase()
{
String upper = "";
for (int i = 0; i < text.length(); i++)
{
String ch = text.substring(i, i + 1);
if ( isUpperCase(ch))
{
upper = upper + ch;
}
}
return upper;
}
public boolean isUpperCase(String str)
{
return Character.isUpperCase(str.charAt(0));
}
public int getECount()
{
}
public String initials ()
{
}
}
Explanation / Answer
LoopyText.java
public class LoopyText {
private String text;
public LoopyText(String theText)
{
text = theText;
}
public String getText()
{
return text;
}
public String getUpperCase()
{
String upper = "";
for (int i = 0; i < text.length(); i++)
{
String ch = text.substring(i, i + 1);
if ( isUpperCase(ch))
{
upper = upper + ch;
}
}
return upper;
}
public boolean isUpperCase(String str)
{
return Character.isUpperCase(str.charAt(0));
}
public int getECount()
{
int count = 0;
for(int i=0;i<text.length();i++) {
if(text.toLowerCase().charAt(i)=='e') {
count++;
}
}
return count;
}
public String initials ()
{
String s = "";
if(text.length()>0) {
s = s + text.charAt(0);
}
int fromIndex=s.indexOf(" ");
while(fromIndex != -1) {
s=s+text.charAt(fromIndex+1);
fromIndex=s.indexOf(" ",fromIndex);
}
return s;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.