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

Videos

Expert Solution & Answer
Book Icon
Chapter 8, Problem 5PE

a.

Explanation of Solution

Program:

File name: “CategorizeStrings.java

//Import necessary header files

import java.util.*;

//Define a class named CategorizeStrings

public class CategorizeStrings

{

    //Define a main method

    public static void main (String[] args)

    {

        //Declare the variables and initialize the values

        final int MAX = 20;

        final int CUTOFF = 10;

        final String QUIT = "ZZZ";

        String entry;

        int shortSub = 0;

        int longSub = 0;

        //Create an object for Scanner class

        Scanner input = new Scanner(System.in);

/*Declare an array to store each String in one of two lists -

one list for short Strings that are 10 characters or fewer

and another list for long Strings that are 11 characters or more*/

        String[] longStrings = new String[MAX];

        String[] shortStrings = new String[MAX];

        //Prompt the user to enter a String or QUIT

        System.out.print("Enter a string or " +

         QUIT + " to quit >> ");

        entry = input.nextLine();

        /*While the user does not enter QUIT and enter less than MAX*/

        while(!entry.equals(QUIT) && (shortSub + longSub < MAX))

        {

            //If there are 10 characters or fewer

            if(entry.length() <= CUTOFF)

            {

                //Assign the value

                shortStrings[shortSub] = entry;

                //Increment shortSub

                ++shortSub;

            }

            //Else there are 11 characters or more

            else

            {

                //Assign the value

                longStrings[longSub] = entry;

                //Increment longSub

                ++longSub;

            }

            //If the length of the characters is less than MAX

            if(shortSub + longSub < MAX)

            {

                //Prompt the user to enter a String or QUIT

                System...

b.

Explanation of Solution

Program:

File name: “CategorizeStrings2.java

//Import necessary header files

import java.util.*;

//Define a class named CategorizeStrings2

public class CategorizeStrings2

{

    //Define a main method

    public static void main (String[] args)

    {

        //Declare the variables and initialize the values

        final int MAX = 20;

        final int CUTOFF = 10;

        final String QUIT = "ZZZ";

        String entry;

        int spaces;

        int oneWordSub = 0;

        int twoWordsSub = 0;

        int threeWordsSub = 0;

        //Create an object for Scanner class

        Scanner input = new Scanner(System.in);

        /*Declare an array to store each String in one of three lists -

        that contain no spaces, one space, or more*/

        String[] oneWord = new String[MAX];

        String[] twoWords = new String[MAX];

        String[] threeWords = new String[MAX];

        //Prompt the user to enter a String or QUIT

        System.out.print("Enter a string or " +

         QUIT + " to quit >> ");

        entry = input.nextLine();

        //While the user does not enter QUIT and enter the //String less than than MAX

        while(!entry.equals(QUIT) && (oneWordSub + twoWordsSub + threeWordsSub < MAX))

        {

            //Assign the value 0 to spaces

            spaces = 0;

//For loop to be executed until x exceeds the string //length

            for(int x = 0; x < entry.length(); ++x)

            {

                //If the character contains a space

                if(entry.charAt(x) == ' ')

                    //Increment spaces

                    ++spaces;

            }

            //If the entered Strings contain no spaces

            if(spaces == 0)

            {

                //Assign the value

                oneWord[oneWordSub] = entry;

                //Increment oneWordSub

                ++oneWordSub;

            }

            //Else if the entered Strings contain one space

            else

            if(spaces == 1)

            {

                //Assign the value

                twoWords[twoWordsSub] = entry;

                //Increment twoWordsSub

                ++twoWordsSub;

            }

//Else the entered Strings contain more than one //space

            else

            {

                //Assign the value

                threeWords[threeWordsSub] = entry;

                //Increment threeWordsSub

                ++threeWordsSub;

            }

            //If the length of all the entered Strings is less //than MAX

            if(oneWordSub + twoWordsSub + threeWordsSub < MAX)

            {

                //Prompt the user to enter a String or QUIT

                System...

Blurred answer
Students have asked these similar questions
When the FCC added Color Television to the Industry Standards, they went with the system developed in the 1940s by Peter Goldman for CBS.   Question 15 options:   True   False Part of the reason that many critics disliked 1950s gameshows was the fact that gameshows offered one of the few opportunities to see unscripted interactions with "real" (average/non-famous) people on television.   Question 16 options:   True   False The Andy Griffith Show is an example of the "rural revival" shows that become enormously popular on 1960s American television.   Question 19 options:   True   False During the Network Era, the hours before primetime each day were exclusively devoted to locally-produced programming, not programming dictated by an affiliate station's parent network.   Question 20 options:   True   False
Although color television was not added to the industry standard until 1956, CBS had been broadcasting selected special events in color as early as 1950.   Question 1 options:   True   False Two key factors in creating the Network Era of American television were the FCC licensing freeze and ______________.   Question 4 options:   The Quiz Show Scandals   Habitual Viewing   Operation Frontal Lobes   Drop-In Viewing Least Objectionable Programming was designed to embrace the public service-oriented vision of using television to elevate mass culture and enrich viewers.   Question 6 options:   True   False By the end of the 1950s, all three remaining networks (NBC, CBS, & ABC) were broadcasting their entire nightly programming schedule in full color.   Question 9 options:   True   False
7. See the code below and solve the following. public class Test { public static void main(String[] args) { int result = 0; } result = fn(2,3); System.out.println("The result is: + result); // fn(x, 1) = x // fn(x, y) = fn(x, y-1) + 2, when y>1 public static int fn(int x, int y) { if (x <= 1) return x; else return fn(x, y-1) + 2; } } 7-1. This program has a bug that leads to infinite recursion. Modify fn(int x, int y) method to fix the problem. (2 point) 7-2. Manually trace the recursive call, fn(2,3) and show the output (step by step). (2 point) 7-3. Can you identify the Base Case in recursive method fn(int x, int y)? (1 point)
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
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning
Introduction to Linked List; Author: Neso Academy;https://www.youtube.com/watch?v=R9PTBwOzceo;License: Standard YouTube License, CC-BY
Linked list | Single, Double & Circular | Data Structures | Lec-23 | Bhanu Priya; Author: Education 4u;https://www.youtube.com/watch?v=IiL_wwFIuaA;License: Standard Youtube License