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
Suppose a teacher has five students who have taken four tests. The teacher uses the following grading scales to assign a letter grade to a student, based on the average of his or her four test scores. Test Score Letter Grade 90-100 80-89 70-79 60-69 0-59 A B C D F Create an application that uses an array of strings to hold the five student names, an array of five strings to hold each student's letter grades, and five arrays of four single precision numbers to hold each student's set of test scores.
Design a program that allows two players to play a game of tic-tac-toe.  Use a two dimensional String array with three rows and three columns as the game board.  Each element of the array should be initialized with a asterisk (*).  The program should run a loop that does the following: Display the contents of the board array. Allows player 1 to select a location on the board for an X.  The program should ask the user to enter the row and column number.  Allows player 2 to select a location on the board for an O.  The program should ask the user to enter the row and column number. Determines whether a player has won or if a tie has occurred.  If a player has won, the program should declare that player the winner and end.  If a tie has occurred, the program should say so and end.    Player 1 wins when there are three X's in a row on the game board.  Player 2 wins when there are three O's in a row on the game board.  The winning X's or O's can appear in a row, in a column, or diagonally…
2. The Integer.parseInt () method requires a String argument, but fails if the String cannot be converted to an integer. Write an application in which you try to parse a String that does not represent an integer value. Catch the Number FormatException that is thrown, and then display an appropriate error message. Save the file as Try ToParseString.java.
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