Question

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 = {"A", "Angela", "B", "gill", "e", "e"}

Counts would be:

A: 2
n: 1
g: 2
e: 3
l: 3
a: 1

thus the method countItUp would return the integer array {2, 1, 2, 3 ,3, 1}.

INPUT:

All input has been handled for you:

  • A filled 1-D string array called wordFun

METHOD PROCESSING:

Use loops, arrays, and print statements to complete a new method called countItUp . This method should do the following:

  • Read the wordFun array without altering its data
  • Iterate through the wordFun array using a for loop
    • For each string in the array, loop through the letters and determine if any are one of those in my name ('A', 'n', 'g', 'e', 'l', or 'a')
      • Keep a count of the number of occurrences of each of those letters, incrementing every time you see another one.

METHOD RETURN VALUE:

  • Once the the counts have been completed, the method would return those counts as an integer array of the form:

    { COUNT_OF_A, COUNT_OF_n, COUNT_OF_g, COUNT_OF_e, COUNT_OF_l, COUNT_OF_a}


NOTE: Only complete the countItUp method. Do not alter any other code.

Sample input/output:

Method argument Method Return Value

{"A", "Angela", "B", "gill", "e", "e"}

{ 2, 1, 2, 3, 3, 1}

{"Angela", "Bill", "apple", "pear"}

{ 1, 1, 1, 3, 4, 3}

Given code:

import java.util.Scanner;

/**
* @author Angela Siegel
* @date 07/17/2020
*/

public class Question3 {

/**
* countItUp method
*/






   /*=====================================
   || DO NOT ALTER CODE BELOW THIS LINE ||
   =====================================*/

public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String[] words = in.nextLine().split(" ");

char[] letters = {'A','n','g','e','l','a'};
int[] counts = countItUp(words);
  
for (int i=0; i<6; i++) {
System.out.println(letters[i] + ": " + counts[i]);
}
}
}

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

CODE:

import java.util.Scanner;

/**
* @author Angela Siegel
* @date 07/17/2020
*/

public class Main {
  
   /**
   * countItUp method
   */
  
   public static int[] countItUp(String[] words) {
       int counts[] = new int[6]; // Initially assigned to '0'
       for (String word : words) { //Looping through all give words
           for (int i = 0; i < word.length(); i++) { //Looping through each word
               if(word.charAt(i) == 'A') //If character is 'A' then increment 0th index count
                   counts[0]++;
               else if(word.charAt(i) == 'n') //If character is 'n' then increment 1th index count
                   counts[1]++;
               else if(word.charAt(i) == 'g') //If character is 'g' then increment 2th index count
                   counts[2]++;
               else if(word.charAt(i) == 'e') //If character is 'e' then increment 3rd index count
                   counts[3]++;
               else if(word.charAt(i) == 'l') //If character is 'l' then increment 4th index count
                   counts[4]++;
               else if(word.charAt(i) == 'a') //If character is 'a' then increment 5th index count
                   counts[5]++;
           }
       }
       return counts; //returning counts array
   }

   /*
   * =====================================
   || DO NOT ALTER CODE BELOW THIS LINE ||
   * =====================================
   */

   public static void main(String[] args) {
       Scanner in = new Scanner(System.in);
       String[] words = in.nextLine().split(" ");

       char[] letters = { 'A', 'n', 'g', 'e', 'l', 'a' };
       int[] counts = countItUp(words);

       for (int i = 0; i < 6; i++) {
           System.out.println(letters[i] + ": " + counts[i]);
       }
   }
}

CODE SCREENSHOT:

1 import java.util.Scanner; 2 3/** 4 * @author Angela Siegel 5* @date 07/17/2020 6 */ 7 8 public class Main { 9 10 /** 11 * cpublic static void main(String[] args) { Scanner in = new Scanner(System.in); String[] words = in.nextLine().split( ); char

OUTPUT SCREENSHOT:

+ C Output Input optional A Angela B gill e e Accepted 0.1295, 12296KB n A: 2 n: 1 g: 2 e: 3 1: 3 a: 1

Hope this will help you. Let me know, still if you have any queries..

Please rate the answer if you like it. Thanks.

Add a comment
Know the answer?
Add Answer to:
DESCRIPTION: You will be given a 1-D array, called wordFun, of Strings. The array has an...
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
  • 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 2-D string array, called matrix. The array has an unknown...

    DESCRIPTION: You will be given a 2-D string array, called matrix. The array has an unknown number of cells filled with data. Your goal is to iterate through the 2-D array and keep a count of how many cells contain the string "Angela". INPUT: All input has been handled for you: A filled 2-D string array. PROCESSING: Determine the number of rows in the array matrix Determine the number of columns in the array matrix Use nested loops to iterate...

  • DESCRIPTION: The purpose of this question is offload processing from the main method to a static...

    DESCRIPTION: The purpose of this question is offload processing from the main method to a static helper method. You will be given the main method. Do not alter this code. Your goal is to write a new method called oddOneOut, which will accept a String, and print it in out every other letter. For example, if the String was "abcdefghijk", the oddOneOut method will return "acegik" . METHOD INPUT: A string METHOD PROCESSING: Do not alter the  main method. Complete the...

  • 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....

  • /**    Given a String and an array of two Strings,    return a three String...

    /**    Given a String and an array of two Strings,    return a three String array containing the strings in alphabetical order.    Note: Capital letters count    sort3Strings("wallace", {"washington", "irving"}) -> {"irving", "wallace", "washington"}    sort3Strings("wallace", {"washington", "Irving"}) -> {"Irving", "wallace", "washington"}    sort3Strings("Washington", {"irving", wallace"}) -> {"Washington", "irving", "wallace"}    sort3Strings("washington", {"washington", "Washington"}) -> {"Washington", "washington", "washington"} **/ public static String[] sort3Strings(String stringValue, String[] stringArray) {    //your code here    return new String[1]; }//end sort3Strings   ...

  • JAVA PLEASE! Write a method called displayPets that takes an array of strings as input. The...

    JAVA PLEASE! Write a method called displayPets that takes an array of strings as input. The method should display the contents of the pets array on one line. Each name should be separated by a space. Use an enhanced for loop to iterate the array. Make sure to declare modifier, parameters and return values. Given an array String[] pets = {"Lucky", "Slinger", "Beast", "Trumpet", "Lulu", "Shadow", "Daisy"} A sample run when calling displayPets(pets) from main() would look like: Pets names:...

  • Java, please. Work based on the code above. DESCRIPTION: The purpose of this question is offload...

    Java, please. Work based on the code above. DESCRIPTION: The purpose of this question is offload processing from the main method to a static helper method. You will be given the main method. Do not alter this code. Your goal is to write a new method called oddOneOut, which will accept a String, and print it in out every other letter. For example, if the String was "abcdefghijk", the oddOneOut method will return "acegik" METHOD INPUT: • A string METHOD...

  • Must be done in Java. Provide the rest of the code with full comments and explanation and with proper indentation. Use...

    Must be done in Java. Provide the rest of the code with full comments and explanation and with proper indentation. Use simple methods for better understanding. Must compile. CODE PROVIDED: import java.util.ArrayList; import java.util.Scanner; public class Problem3 {    public static void main( String [] args ) {        Scanner in = new Scanner( System.in );        //PLEASE START YOUR WORK HERE        //**********************************************************                                                  //**********************************************************        // PLEASE END YOUR WORK HERE        System.out.print("END OF OUTPUT");    } } 20 points! PROBLEM 3: EXTENDED FAMILY Complete this...

  • In this same program I need to create a new method called “int findItem(String[] shoppingList, String...

    In this same program I need to create a new method called “int findItem(String[] shoppingList, String item)” that takes an array of strings that is a shopping list and a string for an item name and searches through the “shoppingList” array for find if the “item” exists. If it does exist print a confirmation and return the item index. If the item does not exist in the array print a failure message and return -1. import java.util.Scanner; public class ShoppingList...

  • JAVA QUESTION I have an array String array [] = {"101", "010", 111"} I have an...

    JAVA QUESTION I have an array String array [] = {"101", "010", 111"} I have an input of "000" that I want to compare to each value in the array and count how many times they Differ. So String input = "000" CODE A FUNCTION THAT ACCEPTS THE ARRAY AND THE INPUT VARIABLE AS PARAMETERS. IN THIS FUNCTION, CODE A FOR LOOP THAT COMPARES THE String input to each element of the array ,COUNTS how many time they differ for...

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