Initialized the array of words by an assignment statement.

Assignment Help JAVA Programming
Reference no: EM13168067

modify the following program . The program from Lab 4 initialized the array of words by an assignment statement.

Modify the program so that it will read from a file, and the name of the file is given as

a command line argument. For example, if the name of the input file is lab4input.txt,

you would run the program using:

c:>java Lab4Program1 lab5input.txt

each command line argument is stored in the

String array of the main method ("args[]"). If the line below is used to run the

program, args[0] should contain the String "lab4input.txt".

 

 

 

import javax.swing.*;

public class Lab4Program1 {


public static void main(String[] args) {

String[] wordArray = { "hello", "goodbye", "cat", "dog", "red", "green", "sun", "moon" };
String isOrIsNot, inputWord;
while(true){
// 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(inputWord.equals("STOP"))
System.exit(0);
// 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

public static boolean wordIsThere(String findMe, String[] theList) {
for(int i=0;i<theList.length;i++)
if(findMe.equals(theList[i]))
return true;
return false;
} // wordIsThere
} // class Lab4Program1

 

 

Reference no: EM13168067

Questions Cloud

State what is the equilibrium constant for the reaction : What is the equilibrium constant for the reaction N2(g) + 3 H2(g) ?? 2 NH3(g) at this temperature?
A and b, both of which perform the same function : Assume you have two algorithms, A and B, both of which perform the same function,
Compute the amount of heat energy required to convert : Calculate the amount of heat energy required to convert 55.0 g of water at 62.5 degrees Celsius to steam at 124.0 degrees Celsius
Write a program that reads in a text file and then computes : Write a program that reads in a text file and then computes and prints a table of letter frequencies. For example, if the file is the text of "A Tale of Two Cities", found in the file at data/tales.txt , the program will print
Initialized the array of words by an assignment statement. : modify the following program . The program from Lab 4 initialized the array of words by an assignment statement.
There are four conditions that are necessary : There are four conditions that are necessary for a deadlock to occur. Give an example to show that these conditions are not sufficient for a resource deadlock to occur. When are these conditions sufficient for a resource deadlock to occur? Explain..
Explain the net chemical equation : When a strong base is added to a solution of CuSO4, which is pale blue, a precipitate forms and the solution above the precipitate is colorless. The net chemical equation is Cu(2+)(aq) + 2OH(-)(aq) --> Cu(OH)2(s)
A game of tic-tac-toe : A game of tic-tac-toe, two players (one the computer) take turns marking an available cell in a 3 X 3 grid (a two dimensional array) with their respective tokens (either and X or an O). When one player has placed three tokens in a horizontal
Define the heat of combustion is transferred to the water : how many liters of C6H14(l) measured at 20 degC must be burned to provide enough heat to warm 26.9m^3 of water from 17.7 to 32.6degC .

Reviews

Write a Review

JAVA Programming Questions & Answers

  Modify each sorting algorithm

Modify each sorting algorithm so that it keeps track of the number of comparisons it performs and the number of exchanges (swaps) it performs during a single sorting operation. Keep track of these numbers using two long integer counters

  What is overloading and what is overriding

What is overloading and what is overriding? Please use code to explain it.

  The array at the index method

have an array, how do i remove an entry from the array at the index method?

  Have an array of integers with user input instead of given

change the current code to have an array of integers with user input intead of given input from the main where it says int[] a=....; And also from a text file but the same numbers as what is given in main.

  Compute the temperature in centigrade

Compute the temperature in Centigrade - Display the temperatures in both Centrigrade and Fahrenheit with appropriate labels, using the + operator to concatenate the labels with the variables

  Write program in java-calculate and display mortgage payment

Write the program in Java (with a graphical user interface) and have it calculate and display the mortgage payment amount from user input of the amount of the mortgage.

  A client or server prepare to use udp in a java application

How does a client or server prepare to use UDP in a Java application? Are there any differences in what the client does and what the server does?

  Loops and files

Convert an algorithm using control structures into Java and write a while loop

  Web engineering principles

web application development, Web Engineering methodology, UML-based Web Engineering (UWE), models to the expansion of web applications, Object Oriented Web Solutions (OOWS),Web Modeling Language (WebML) methodology, Object-Oriented Hypermedia Design..

  Identify the 5 code elements

Identify the 5 code elements for a Password class. Things like: class, instance, and final variables, accessor and mutator method, public and private specifiers for methods and member variables.i need to provide detail and descriptions for each code ..

  The main method must repeatedly have the use

After the method is defined, the main method must repeatedly have the user enter 3 integers, call the triangleType method and display the return type. Be sure not to have an infinite loop by allowing the user to quit.

  Develop a graphical user interface based java program

Develop a Java program that can communicate with a real SMTP email server for sending emails. TNE 60003 - introduction to network programming, You program should provide a GUI and can successfully send the SMTP commands to the mail server

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd