Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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 ()
   {
  
   }
}

Complete the class LoopyText which has a constructor that takes a String of text. Implement the following methods. public String getText () returns the text public string getUpperCase) gets a String consisting of the uppercase letters in the text. You are provided with a helper method, isUpperCase () which takes a String consisting of one character public int getECount ) gets the number of e's in the String, either upper or lower case. Do not change the instance variable public String initials ) that returns a string consisting of the first character of every word in the string. If the string is the empty string, return the empty String. Hint: Each word after the first is preceded by a space. You can use the String method indexof (" ", fromIndex) to control the loop and to determine where a new word starts. Remember indexOf returns -1 if the space is not in the search string

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;

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote