EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
9th Edition
ISBN: 9781337671385
Author: FARRELL
Publisher: CENGAGE LEARNING - CONSIGNMENT
bartleby

Concept explainers

Expert Solution & Answer
Book Icon
Chapter 9, Problem 1PE

a.

Explanation of Solution

Program:

File name: “StringSort.java

//Import necessary header files

import java.util.*;

import javax.swing.*;

//Define a class named StringSort

public class StringSort

{

    //Define main method

    public static void main(String[] args)

    {

        //Create an array of 15 string values

String[] values =  {"mouse", "dog", "cat", "horse", "cow",

         "moose", "tiger", "lion", "elephant", "bird", "hamster",

         "guina pig", "leopard", "aardvark", "hummingbird"};

        //Declare the variable

      ...

b.

Explanation of Solution

Program:

File name: “StringSort2.java

//Import necessary header files

import java.util.*;

import javax.swing.*;

//Define a class named StringSort2

public class StringSort2

{

    //Define main method

    public static void main(String[] args)

    {

        //Create an array of 15 string values

        String[] values = new String[15];

        //Declare the variables and initialize the values

        int x = 0;

        int count = 0;

        String word;

        final String QUIT = "zzz";

        //Declare a Boolean variable and initialize the value

        boolean didUserQuit = false;

/*For loop is executed until x exceeds the length of the given values*/

        for(x = 0; x < values.length; ++x)

            values[x] = QUIT;

        //Assign value 0 to x

        x = 0;

        //While x is less than the length of the given values

        while(x < values.length)

        {

            //Prompt the user to enter a word

word = JOptionPane.showInputDialog(null, "Enter a word or " +

            QUIT + " to quit");

            //If the user enters zzz

            if(word.equals(QUIT))

            {

                count = x;

                x = values...

Blurred answer
Students have asked these similar questions
Create in Java (1) Create an array of String objects and populate it with the days of the week (7 days)(i.e., Monday - Sunday)(2) Create an array parallel to the one created in (1) to store the entrées. However, you do not have this information, soyou will need to write a loop that prompts the user to enter the entrée served on that day. This prompt shouldinclude the day for which you are asking for the information (e.g., "What entrée is being served on Monday?")(3) Create another parallel array that stores the prices. You will also need to collect this information from the user. Thistime, your prompt should include the name of the entrée for which you are asking for the price(4) Prompt the user to choose an entrée from a list that you display numbered 1 through 7 (have them input a number1 to 7) and search the array and output the day on which the entrée will be served(5) Search through the array for the highest price entrée and output the name of this entrée for the user including…
Create a procedure that generates a random string of length L, containing all capital letters. When calling the procedure, pass the value of L in EAX, and pass a pointer to an array of bytes that will hold the random string. Write a test program that calls your procedure 20 times and displays the strings in the console window. Sample Output:
Write a program that prompts the user to input a string and outputs the string in uppercase letters using dynamic arrays.  Given code:  #include <iostream> #include <cstring>  #include <cctype>     using namespace std; int main() {     char str[81];     int len;     int i;     cout << "Enter a string: ";     cin.get(str, 80);     cout << endl;     cout << "String in upper case letters is:" << endl;     len = strlen(str);     for (i = 0; i < len; i++)         cout << static_cast<char>(toupper(str[i]));     cout << endl;     return 0; }
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
  • Text book image
    EBK JAVA PROGRAMMING
    Computer Science
    ISBN:9781337671385
    Author:FARRELL
    Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT