This is a code I'm having trouble using any type of loop. I'm fairly new to java, but towards the bottom when running the program; even if the answer you entered was right and matched the one of the words listed, the code would still return "Word is not there". Basically, I'm trying to make it test wether the word entered is there and if it isn't to respond accordingly. Hopefully, I explained clearly and the code typed out is clear as well. Towards the bottom where i say return false and return true is really where I need help.     import javax.swing.JOptionPane;   public class Lab4 { privatestaticfinalStringinputWord = null;   publicstaticvoidmain(String[]args){   String[]wordArray={"hello","goodbye","cat","dog","red","green","sun","moon"}; StringisOrIsNot,inputWord;   // This line asks the user for input by popping out a single window // with text input inputWord=JOptionPane.showInputDialog(null, "Enter a word in all lower case:");   // if the inputWord is contained within wordArray return true if(wordIsThere(inputWord, wordArray))  isOrIsNot="is";// set to is if the word is on the list else isOrIsNot="is not";// set to is not if the word is not on the list   // Output to a JOptionPane window whether the word is on the list or not JOptionPane.showMessageDialog(null, "The word " + inputWord + " " + isOrIsNot + " on the list."); }//main   @SuppressWarnings("unused") publicstaticbooleanwordIsThere(StringfindMe,String[]theList){   returnfalse;   if(inputWord == String[]) { returntrue; }       }   // wordIsThere } // class Lab4Program1

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

This is a code I'm having trouble using any type of loop. I'm fairly new to java, but towards the bottom when running the program; even if the answer you entered was right and matched the one of the words listed, the code would still return "Word is not there". Basically, I'm trying to make it test wether the word entered is there and if it isn't to respond accordingly. Hopefully, I explained clearly and the code typed out is clear as well. Towards the bottom where i say return false and return true is really where I need help.

 

 

import javax.swing.JOptionPane;

 

public class Lab4 {

privatestaticfinalStringinputWord = null;

 

publicstaticvoidmain(String[]args){

 

String[]wordArray={"hello","goodbye","cat","dog","red","green","sun","moon"};

StringisOrIsNot,inputWord;

 

// This line asks the user for input by popping out a single window

// with text input

inputWord=JOptionPane.showInputDialog(null, "Enter a word in all lower case:");

 

// if the inputWord is contained within wordArray return true

if(wordIsThere(inputWord, wordArray)) 

isOrIsNot="is";// set to is if the word is on the list

else

isOrIsNot="is not";// set to is not if the word is not on the list

 

// Output to a JOptionPane window whether the word is on the list or not

JOptionPane.showMessageDialog(null, "The word " + inputWord + " " + isOrIsNot + " on the list.");

}//main

 

@SuppressWarnings("unused")

publicstaticbooleanwordIsThere(StringfindMe,String[]theList){

 

returnfalse;

 

if(inputWord == String[]) {

returntrue;

}

 

 

 

}

 

// wordIsThere

} // class Lab4Program1

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education