Question

package week_3; /** Write a method called countUppercase that takes a String array argument. You can...

package week_3;

/**

 Write a method called countUppercase that takes a String array argument.
 You can assume that every element in the array is a one-letter String, for example
 String[] test = { "a", "B", "c", "D", "e"};

 This method will count the number of uppercase letters from the set A through Z in the array,
 and return that number.  So for the example array above, your method will return 2.

 You will need to use some Java library methods. You may need some methods from
 some or all of these library classes: String, Character, Integer.
 
 COMMENT YOUR CODE. As well as the tests, the instructor will also read your comments
 to verify that you understand and can describe the code you've written.
 
 */



public class Question_5_Count_Uppercase_Letters {

    public static void main(String[] args) {
        new Question_5_Count_Uppercase_Letters().countUppercaseLetters();
    }

    private void countUppercaseLetters() {

        // You can call your new countUppercase() method with these example arrays.

        String[] test1 = { "a", "b", "c" };  // no uppercase letters - your method should return 0
        String[] test2 = { "a", "B", "c", "D", "e" };  // two uppercase letters - your method should return 2
        String[] test3 = { "A", "B", "C", "D" };  // four uppercase letters - your method should return 4
        String[] test4 = { "$", "B", "c", "6", "D", "\n", "E" };  // three uppercase letters - your method should return 3

        // You don't need any user input in this program.
    }


    /*

    TODO Create a public method called countUppercase.

    This method should take a String array argument, and return an int.

    This method should count the number of uppercase letters - in the range A through Z - and return that count.

    */



}
0 0
Add a comment Improve this question Transcribed image text
Answer #1
package week_3;
/**

 Write a method called countUppercase that takes a String array argument.
 You can assume that every element in the array is a one-letter String, for example
 String[] test = { "a", "B", "c", "D", "e"};

 This method will count the number of uppercase letters from the set A through Z in the array,
 and return that number.  So for the example array above, your method will return 2.

 You will need to use some Java library methods. You may need some methods from
 some or all of these library classes: String, Character, Integer.

 COMMENT YOUR CODE. As well as the tests, the instructor will also read your comments
 to verify that you understand and can describe the code you've written.

 */



public class Question_5_Count_Uppercase_Letters {

  public static void main(String[] args) {
    new Question_5_Count_Uppercase_Letters().countUppercaseLetters();
  }

  private void countUppercaseLetters() {

    // You can call your new countUppercase() method with these example arrays.

    String[] test1 = { "a", "b", "c" };  // no uppercase letters - your method should return 0
    String[] test2 = { "a", "B", "c", "D", "e" };  // two uppercase letters - your method should return 2
    String[] test3 = { "A", "B", "C", "D" };  // four uppercase letters - your method should return 4
    String[] test4 = { "$", "B", "c", "6", "D", "
", "E" };  // three uppercase letters - your method should return 3

    System.out.println(countUppercase(test1));
    System.out.println(countUppercase(test2));
    System.out.println(countUppercase(test3));
    System.out.println(countUppercase(test4));
    // You don't need any user input in this program.
  }


    /*

    TODO Create a public method called countUppercase.


    This method should take a String array argument, and return an int.

    This method should count the number of uppercase letters - in the range A through Z - and return that count.

    */

    public static int countUppercase(String arr[]){
      int count = 0;
      for(int i = 0;i<arr.length;i++){
        if(arr[i].charAt(0) >= 'A' && arr[i].charAt(0) <= 'Z'){
          count++;
        }
      }
      return count;
    }


}

0
2
4
3

Add a comment
Know the answer?
Add Answer to:
package week_3; /** Write a method called countUppercase that takes a String array argument. You can...
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
  • This method takes an array of Strings as a parameter and has no return value. The...

    This method takes an array of Strings as a parameter and has no return value. The purpose of this method is to count all the characters in an array of strings. Count the number of characters in every string in the array and assign to numberChars. Count the number of lowercase letters in every string in the array and assign to numberLower. Count the number of uppercase letters in every string in the array and assign to numberUpper. Count characters...

  • Implement the squeeze() method in the provided ArraySqueeze class so that it performs as indicated in...

    Implement the squeeze() method in the provided ArraySqueeze class so that it performs as indicated in the comment. The main() method in this class runs some test cases on squeeze(). You should also add a few nontrivial and interesting test cases of your own at the end of main(). package A1; /** * The purpose of this class is to squeeze an array of ints. * * The main method runs some tests. * * @author andy * */ public...

  • Write a method called printReverse() that takes a string and uses recursion to print the contents...

    Write a method called printReverse() that takes a string and uses recursion to print the contents of the string in reverse order. The string itself should not be reversed; it must be left in its original form. The method has the following header:   void printReverse(String s, int i) where s is a reference to the string, and i is an integer parameter that you may use as you see fit. You do not need to code up this method as...

  • Lab 3 Step One First, create an empty directory for lab3. There is no starter code for this lab. You will be throwing an...

    Lab 3 Step One First, create an empty directory for lab3. There is no starter code for this lab. You will be throwing and catching exceptions in this exercise. Create a file called RuntimeException.h and put the following code in it. #include <string> class RuntimeException { private: string errorMsg; public: RuntimeException(const string& err) { errorMsg = err; } string getMessage() const { return errorMsg; } } Step Two In a new .cpp file in your directory, write a main function...

  • DESCRIPTION: You will be given a 1-D array, called wordFun, of Strings. The array has an...

    DESCRIPTION: You will be given a 1-D array, called wordFun, of Strings. The array has an unknown number of cells filled with data. As before, the array will already be filled with strings, some of which contain the string "Angela". You will create a method called countItUp which returns and integer array containing the number of times each of the letters in my name occur within the strings within this array. For example, if the input array was wordFun =...

  • DESCRIPTION: You will be given a 1-D array, called wordFun, of Strings. The array has an...

    DESCRIPTION: You will be given a 1-D array, called wordFun, of Strings. The array has an unknown number of cells filled with data. As before, the array will already be filled with strings, some of which contain the string "Angela". You will create a method called countItUp which returns and integer array containing the number of times each of the letters in my name occur within the strings within this array. For example, if the input array was wordFun =...

  • RUBY! \Write a method called reverse_each_word that takes in a string argument of a sentence and...

    RUBY! \Write a method called reverse_each_word that takes in a string argument of a sentence and returns that same sentence with each word reversed in place. First solve it using .each Then utilize the same method using .collect to see the difference. For example: reverse_each_word("Hello there, and how are you?") #=> "olleH ,ereht dna woh era ?uoy" Hint: You can't use an enumerator on a string, so how can we turn our string into an array? Hint: How can we...

  • You will write three static methods to manipulate an input String in different ways using various...

    You will write three static methods to manipulate an input String in different ways using various String methods. You need to provide the code for each of the three static methods in class StringPlay (requirements for each listed below). You will also change the control statement in the test harness to allow for variations in the sentinel value. You need to modify the loop control condition in Lab09.java so that user inputs of ‘finish’, “FINISH”, “FiniSH”, “fINISH”, etc. will end...

  • I’m giving you code for a Class called GenericArray, which is an array that takes a...

    I’m giving you code for a Class called GenericArray, which is an array that takes a generic object type. As usual this is a C# program, make a new console application, and for now you can stick all of this in one big file. And a program that will do some basic stuff with it Generic Array List What I want you to do today: Create methods for the GenericArray, Easy(ish): public void Append (T, value) { // this should...

  • Write a cell method that takes a single double as an argument and returns an int....

    Write a cell method that takes a single double as an argument and returns an int. The int should be the next highest whole integer (eg 3.14 would return 4). Use math not built-in Java methods mins) Write a method that takes a string as an argument. It your string is more than 10 letters or less than 1 letter return "Bad number". Otherwise, return the telephone number equivalent of the input. Your return can be of type String Eg...

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
ADVERTISEMENT