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

write a program which include a class containing an array of words (strings).The

ID: 3576642 • Letter: W

Question

write a program which include a class containing an array of words
(strings).The program will search the array for a specific word. if it finds the word:it will return a true value.if the array does not contain the word. it will return a false value.

enhancements:

make the array off words dynamic, so that the use is prompter to enter the list of words.

make the word searcher for dynamic, so that a different word can be searched for each run

produce a total count of the number of time the word is found, so that if the word is found more than once in the array, atotal count is porduced

All above are the question:Below are what i typed, can you teach me how to fix it. there are no error but i cannot finish some questions above

import java.util.Scanner;
import javax.swing.JOptionPane;
public class Davidhw1
{
public static void main(String[] args)
{String name;
   // Description of the program
   JOptionPane.showMessageDialog( null, " This program calls a method to search an array for the word ");
       //create an array
   String [] list= new String[10];
   Scanner scan= new Scanner(System.in);
for (int x=0;x<10;x++)//create a list
{
   System.out.print("Enter name:");name=scan.nextLine();
   list[x]=name;
}
int t=0;
for(int i=0;i<list.length;i++)
{System.out.print("Enter the word you want to search:");
String x=scan.nextLine();//enter the word you want to search
if(list[i].contains("x"))
{
   t=t+1;
   System.out.println("The word is in the array");
}
}
if (t > 0)
{
System.out.print( "The word exists in the Array");

}
else{
   //not found
   System.out.println("The word is not in the array");

Explanation / Answer

/*Modified java program that prompts user to enter
number of string to enter and then prompts the strings
and then prompt for the search string and then prints
the count of the string in the list */
//Davidhw1.java
import java.util.Scanner;
import javax.swing.JOptionPane;
public class Davidhw1
{
   public static void main(String[] args)
   {
       //Create a scanner class object to read input from keyword
       Scanner scan= new Scanner(System.in);  
       String name;
       // Description of the program
       JOptionPane.showMessageDialog( null,
               " This program calls a method to search an array for the word ");
       //Declare an array of type string
       String[] list;
       //declare an integer variable,N
       int N;

       System.out.println("Enter number of words to read from keyword");      
       //prompt user to enter size of the array and convert to ineger
       N=Integer.parseInt(scan.nextLine());

       //create array list of dynamic size ,N
       list=new String[N];

       //read names from user
       for (int i=0;i<N;i++)//create a list
       {
           System.out.print("Enter name:");
           name=scan.nextLine();
           list[i]=name;
       }

       System.out.print("Enter the word you want to search:");
       //enter the word you want to search
       String searchName=scan.nextLine();

       //Calling method searchName passing list and searchName as input
       //arguments
       int result=searchName(list,searchName);
       //Check if result is 0
       if (result==0)
       {          
           System.out.println("The word is not in the array");          
       }
       else{
           //othrewise print number of times the search name in the list
           System.out.print( "The word exists in the Array "+result+" times");
       }
   }

   /**
   * The method searchName that takes an array of string type
   * and search word and finds the number of times the word
   * x contains in the string array list and
   * return the count to calling method.
   * */
   public static int searchName(String[] list, String x) {      

       //set count=0
       int count=0;
       for(int i=0;i<list.length;i++)
       {          
           if(list[i].contains(x))
           {
               //increment count by 1
               count=count+1;      
           }
       }
       //return count
       return count;
   }//end of method searchName

}//end of the class

------------------------------------------------------------------------------------

Sample output:

Enter number of words to read from keyword
3
Enter name:apple
Enter name:apple
Enter name:orange
Enter the word you want to search:apple
The word exists in the Array 2 times