Java Programming
Java Programming
8th Edition
ISBN: 9781305981829
Author: Joyce Farrell
Publisher: Cengage Limited
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
After our initial deployment for our ML home based security system, the first steps we took to contribute further to the project, we conducted load testing, tested and optimize for low latency, and automated user onboarding. What should be next?
Why investing in skills and technology is a critical factor in the financial management aspect of system projects.
why investing in skills and technology is a critical factor in the financial management aspect of systems projects.
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
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning