JAVA PPROGRAM ASAP   Please Modify this program ASAP BECAUSE IT IS MY LAB ASSIGNMENT so it passes all the test cases. It does not pass the test cases when I upload it to Hypergrade. Because RIGHT NOW IT PASSES 0 OUT OF 1 TEST CASES. I have provided the failed the test cases and the inputs as a screenshot. The program must pass the test case when uploaded to Hypergrade.   import java.util.Scanner; // creating class WordCounter public class WordCounter {     public static void main(String[] args)     {         // creating a scanner object         Scanner sc = new Scanner(System.in);         // if while loop is true         while (true)         {             // then enter a string             System.out.print("Please enter a string or type QUIT to exit:\n");             // Taking string as user input             String str = sc.nextLine();             // if user enters quit then ignore the case             if (str.equalsIgnoreCase("QUIT")) {                 break;             }             // Counting the words present in inputted string and store it in count variable             int count = countWords(str);             // print rhe number of words in the given string             System.out.println("There are " + count + " words in that string.\n");         }         sc.close();     }     // creating a method countWords for counting the words     public static int countWords(String input)     {         // counting the words which are splitted with space         String[] words = input.split(" ");         // Return the length of the words         return words.length;     } } Test Case 1 Please enter a string or type QUIT to exit:\n Hello World!ENTER There are 2 words in that string.\n Please enter a string or type QUIT to exit:\n I have a dream.ENTER There are 4 words in that string.\n Please enter a string or type QUIT to exit:\n Java is great.ENTER There are 3 words in that string.\n Please enter a string or type QUIT to exit:\n quitENTER

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter7: Characters, Strings, And The Stringbuilder
Section: Chapter Questions
Problem 10RQ
icon
Related questions
Question
JAVA PPROGRAM ASAP
 
Please Modify this program ASAP BECAUSE IT IS MY LAB ASSIGNMENT so it passes all the test cases. It does not pass the test cases when I upload it to Hypergrade. Because RIGHT NOW IT PASSES 0 OUT OF 1 TEST CASES. I have provided the failed the test cases and the inputs as a screenshot. The program must pass the test case when uploaded to Hypergrade.
 

import java.util.Scanner;
// creating class WordCounter
public class WordCounter
{
    public static void main(String[] args)
    {
        // creating a scanner object
        Scanner sc = new Scanner(System.in);
        // if while loop is true
        while (true)
        {
            // then enter a string
            System.out.print("Please enter a string or type QUIT to exit:\n");
            // Taking string as user input
            String str = sc.nextLine();
            // if user enters quit then ignore the case
            if (str.equalsIgnoreCase("QUIT")) {
                break;
            }
            // Counting the words present in inputted string and store it in count variable
            int count = countWords(str);
            // print rhe number of words in the given string
            System.out.println("There are " + count + " words in that string.\n");
        }
        sc.close();
    }
    // creating a method countWords for counting the words
    public static int countWords(String input)
    {
        // counting the words which are splitted with space
        String[] words = input.split(" ");
        // Return the length of the words
        return words.length;
    }
}

Test Case 1

Please enter a string or type QUIT to exit:\n
Hello World!ENTER
There are 2 words in that string.\n
Please enter a string or type QUIT to exit:\n
I have a dream.ENTER
There are 4 words in that string.\n
Please enter a string or type QUIT to exit:\n
Java is great.ENTER
There are 3 words in that string.\n
Please enter a string or type QUIT to exit:\n
quitENTER
 
 
 
Test Case 1 Failed Show what's missing
Please enter a string or type QUIT to exit: \n
Hello World! ENTER
There are 2 words in that string.\n
Please enter a string or type QUIT to exit: \n
I have a dream. ENTER
There are 4 words in that string.\n
Please enter a string or type QUIT to exit: \n
Java is great. ENTER
There are 3 words in that string.\n
Please enter a string or type QUIT to exit: \n
quit ENTER
Transcribed Image Text:Test Case 1 Failed Show what's missing Please enter a string or type QUIT to exit: \n Hello World! ENTER There are 2 words in that string.\n Please enter a string or type QUIT to exit: \n I have a dream. ENTER There are 4 words in that string.\n Please enter a string or type QUIT to exit: \n Java is great. ENTER There are 3 words in that string.\n Please enter a string or type QUIT to exit: \n quit ENTER
Test Case 1 Failed Show what's missing
Please enter a string or type QUIT to exit: \n
Hello World! ENTER
There are 2 words in that string. \n
|\n
Please enter a string or type QUIT to exit: \n
I have a dream. ENTER
There are 4 words in that string. \n
|\n
Please enter a string or type QUIT to exit: \n
Java is great. ENTER
There are 3 words in that string.\n
|\n
Please enter a string or type QUIT to exit: \n
quit ENTER
Transcribed Image Text:Test Case 1 Failed Show what's missing Please enter a string or type QUIT to exit: \n Hello World! ENTER There are 2 words in that string. \n |\n Please enter a string or type QUIT to exit: \n I have a dream. ENTER There are 4 words in that string. \n |\n Please enter a string or type QUIT to exit: \n Java is great. ENTER There are 3 words in that string.\n |\n Please enter a string or type QUIT to exit: \n quit ENTER
Expert Solution
steps

Step by step

Solved in 5 steps with 3 images

Blurred answer
Knowledge Booster
Unreferenced Objects
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
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT