Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

Linear Search algorithm. Your program will ask the user to input 10 letters (e.g., e, c, z, x, k, m, o, a, d, f). The program will store these 10 letters into an array. Then the program will ask the user which letter the user wants to search for. If the letter is in the array, the program should return the position of the letter in the array. If the letter is NOT in the array, the message "Letter not found" should display. The user must press "E" to exit. and lastly its has to be a GUI.

import javax.swing.JOptionPane;

public class LetterSearchGUI {

 public static int search(String[] arr, String key) {

  int size = arr.length;

  for (int i = 0; i < size; i++) {

   if (key.equalsIgnoreCase(arr[i])) {

    return i;

   }

  }

  return -1;

 }

 public static void main(String a[]) {

  do {

   String[] input = new String[10];

   for (int i = 0; i < 10; i++) {

    input[i] = JOptionPane.showInputDialog("Enter the letter "

      + (i + 1) + ": ");

   }

   String searchKey = JOptionPane

     .showInputDialog("Enter the letter the user wants to search for: ");

   int pos = search(input, searchKey);

   if (pos == -1) {

    JOptionPane.showMessageDialog(null, "Letter not found");

   } else {

    JOptionPane.showMessageDialog(null, "Key " + searchKey

      + " found at index: " + pos);

   }

 

   // string for exit button

   String s = JOptionPane

     .showInputDialog("Press E to exit the program or anything to continue: ");

   if ("E".equalsIgnoreCase(s)) {

    break;

   }

  } while (true);

 }

}

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M92630523
  • Price:- $10

Priced at Now at $10, Verified Solution

Have any Question?


Related Questions in Computer Engineering

One of the basic motivations behind the minimum spanning

One of the basic motivations behind the Minimum Spanning Tree Problem is the goal of designing a spanning network for a set of nodes with minimum  total  cost. Here we explore another type of objective: designing a spann ...

How to design a java program that reads a sentence say s

How to design a Java program that reads a sentence, say s, consisting of lower-case words with .nextLine() method, identifies the words using .indexOf() and .substring() methods and saves them in String variables. Then t ...

Submit a 2- to 3-page paper in which youidentify an

Submit a 2- to 3-page paper in which you: Identify an intercultural area Intercultural interaction with a person from a culture different from your own. Explain why you have selected this area. Describe your personal cul ...

Explain how the company newmans own brand fulfills the

Explain how the company Newman's Own brand fulfills the definition of a business for profit and a non-profit business at the same time. Consider in the response the functions of business, entrepreneurship and production ...

Question suppose a computer using direct mapped cache has

Question : Suppose a computer using direct mapped cache has 2 20 words of main memory and a cache of 32 blocks, where each cache block contains 16 words. a. How many blocks of main memory are there? b. What is the format ...

How would the stock market soars and americans wealth

How would the stock market soars and Americans wealth expands significantly affect the econmony, by analyzing in the SRAS-AD diagram and determine the effects on real GDP and the General price level.

Question define a class named taxreturn that contains a tax

Question : Define a class named TaxReturn that contains a tax ID number, last name, first name, annual income, number of dependents, and amount of tax owed for a taxpayer. Include constant static fields that

Question body image please respond to the followingdebate

Question: "Body Image" Please respond to the following: Debate It - take a position on this statement: Media cause individuals to develop negative and unrealistic body images. Support your views with two or three reasons ...

The rate of inflation in year 1 is expected to be 14 year

The rate of inflation in year 1 is expected to be 1.4%, year two is 1.8%, and years three through five is expected to be 2%. Assume the real risk-free rate, r*, is 3% for all maturities. What should the yield to maturity ...

Information systemsdirections answer the following if you

Information Systems Directions : Answer the following: If you were asked to develop a logical model of the registration system at a school, would it be better to use a top-down or bottom-up approach? Explain your reasoni ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As