Question

Complete the class LoopyText. The constructor has been completed and provided to you in Codecheck. public...

Complete the class LoopyText. The constructor has been completed and provided to you in Codecheck.

  • public LoopyText(String theText) Constructs an object of LoopyText and stores theText inside the object. The parameter theText is a string with zero or more words separated by single spaces.
  • public String getEverySecondCharacter() Returns a string consisting of every other character, starting with the character at index 0. If the string is the empty string return the empty String.
  • public int upperCaseCount() Returns the number of uppercase letters in the text.
  • public String firstLetters() 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.

For the draft, implement the getEverySecondCharacter()method

Code template:

/**
* Provides some methods to manipulate text
*
*/
public class LoopyText
{
private String text;
  
/**
* Creates a LoopyText object with the given text
* @param theText the text for this LoopyText
*/
public LoopyText(String theText)
{
text = theText;
}
  
//Your methods here
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

public class LoopyText {
   private String text;
//   Constructs an object of LoopyText and stores theText inside the object. The parameter theText is a string with zero or more words separated by single spaces.
   public LoopyText(String theText) {
       text = theText;
   }
  
//   Returns a string consisting of every other character, starting with the character at index 0. If the string is the empty string return the empty String.
   public String getEverySecondCharacter()
   {
       String resultString = "";
       if(text==null || text=="") return "";
       else
       {
           String word[] = text.split(" ");
           for(String i:word)
           {
               resultString+=i.charAt(1);
           }
       }
       return resultString;
   }
  
//   Returns the number of uppercase letters in the text.
   public int upperCaseCount()
   {
       int upperCaseCount = 0;
       for (int k = 0; k < text.length(); k++)
       {
       if (Character.isUpperCase(text.charAt(k))) upperCaseCount++;
       }
       return upperCaseCount;
   }
  
//   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.
   public String firstLetters()
   {
       String resultString = "";
       if(text==null || text=="") return "";
       else
       {
           String word[] = text.split(" ");
           for(String i:word)
           {
               resultString+=i.charAt(0);
           }
       }
       return resultString;
   }
  
   public static void main(String[] args) {
       LoopyText obj = new LoopyText("this is Some Text");
       System.out.println("Input Text = "+obj.text);
       System.out.println("getEverySecondCharacter = "+obj.getEverySecondCharacter());
       System.out.println("upperCaseCount = "+obj.upperCaseCount());
       System.out.println("firstLetters = "+obj.firstLetters());
   }
}

Add a comment
Know the answer?
Add Answer to:
Complete the class LoopyText. The constructor has been completed and provided to you in Codecheck. public...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Given code: /** * Provides some methods to manipulate text * */ public class LoopyText {...

    Given code: /** * Provides some methods to manipulate text * */ public class LoopyText { private String text;    /** * Creates a LoopyText object with the given text * @param theText the text for this LoopyText */ public LoopyText(String theText) { text = theText; }    //Your methods here } Given tester code: /** * Tests the methods of LoopyText. * @author Kathleen O'Brien */ public class LoopyTextTester { public static void main(String[] args) { LoopyText loopy =...

  • Write a class StringsAndThings. The class has one instance variable of type String and a constructor...

    Write a class StringsAndThings. The class has one instance variable of type String and a constructor with a parameter to initialize the instance variable. The parameter could contain any characters, including letters, digits, spaces, special characters (+, -, $, @,...), and punctuation marks. Write methods: countNonLetters - that will count how many of the characters in the string are not letters. You can use Character's isLetter method. moreVowels - which returns true if the String parameter has more vowels than...

  • Create a class named Module2. You should submit your source code file (Module2.java). The Module2 class...

    Create a class named Module2. You should submit your source code file (Module2.java). The Module2 class should contain the following data fields and methods (note that all data and methods are for objects unless specified as being for the entire class) Data fields: A String object named firstName A String object named middleName A String object name lastName Methods: A Module2 constructor method that accepts no parameters and initializes the data fields from 1) to empty Strings (e.g., firstName =...

  • Create a LIFO class with following methods in java - public LifoList() The default constructor for...

    Create a LIFO class with following methods in java - public LifoList() The default constructor for LifoList class which will initialize your class variables maxSize to 0 and the int array to null. public LifoList(int maxSize) The constructor for LifoList class which takes the int input maxSize to initialize the size of the array. You should NOT reinitialize the array elsewhere. For example, creating an object as new LifoList(5) should create a LifoList whose maximum size is 5. If the...

  • /** * A recursive representation of a tower of blocks. * * */ public class Tower{...

    /** * A recursive representation of a tower of blocks. * * */ public class Tower{     /** The top block. */     private char top;        /** The rest of the tower. */     private Tower rest;     /**      * Creates a new empty Tower.      */     public Tower() {         this.top = ' ';         this.rest = null;     }        /**      * External classes can only create empty towers and manipulate     ...

  • Stack help. I need help with my lab assignment. Complete a method for a class named...

    Stack help. I need help with my lab assignment. Complete a method for a class named Palindrome that evaluates a string phrase to determine if the phrase is a palindrome or not. A palindrome is a sequence of characters that reads the same both forward and backward. When comparing the phrase to the same phrase with the characters in reverse order, an uppercase character is considered equivalent to the same character in lowercase, and spaces and punctuation are ignored. The...

  • This is Crypto Manager blank public class CryptoManager { private static final char LOWER_BOUND = '...

    This is Crypto Manager blank public class CryptoManager { private static final char LOWER_BOUND = ' '; private static final char UPPER_BOUND = '_'; private static final int RANGE = UPPER_BOUND - LOWER_BOUND + 1; /** * This method determines if a string is within the allowable bounds of ASCII codes * according to the LOWER_BOUND and UPPER_BOUND characters * @param plainText a string to be encrypted, if it is within the allowable bounds * @return true if all characters...

  • q2: Write a public class named MythMouseListener that implements the Mouselistener interface. This class will have...

    q2: Write a public class named MythMouseListener that implements the Mouselistener interface. This class will have a public constructor that takes a JTextArea and a JLabel as parameters and stores these in instance variables. Override the mouseEntered method to . display the text from the JTextArea on the JLabel in all upper case letters. Then, override the mouseReleased method to display the text from the JTextArea on the JLabel in all lower case letters. The other three methods from the...

  • In Java. What would the methods of this class look like? StackADT.java public interface StackADT<T> {...

    In Java. What would the methods of this class look like? StackADT.java public interface StackADT<T> { /** Adds one element to the top of this stack. * @param element element to be pushed onto stack */ public void push (T element);    /** Removes and returns the top element from this stack. * @return T element removed from the top of the stack */ public T pop(); /** Returns without removing the top element of this stack. * @return T...

  • JAVA /** * This class stores information about an instructor. */ public class Instructor { private...

    JAVA /** * This class stores information about an instructor. */ public class Instructor { private String lastName, // Last name firstName, // First name officeNumber; // Office number /** * This constructor accepts arguments for the * last name, first name, and office number. */ public Instructor(String lname, String fname, String office) { lastName = lname; firstName = fname; officeNumber = office; } /** * The set method sets each field. */ public void set(String lname, String fname, String...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT