
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...

Trending nowThis is a popular solution!

- 6. See the code below and solve the following. import java.io.*; public class DataStream { } public static void main(String[] args) } DataOutputStream output = new DataOutputStream(new FileOutputStream("temp.dat")); output.writeUTF("Book1"); output.writeInt(85); output.writeUTF("Book2"); output.writeInt(125); output.writeUTF("Book3"); output.writeInt(70); output.close(); // ToDo: Read all data from temp.dat and print the data to the standard output (monitor) 6-1. This program has a compile error, and the message is “Unhandled exception type FileNotFoundException". How do you fix this error? (1 point) 6-2. Is FileNotFoundException a checked exception or an unchecked exception? (1 point) 6-3. What is the difference between checked exception and unchecked exception? (1 point) 6-4. Please complete the above program by reading all data from temp.dat and print the data to the standard output (monitor) by using System.out.print, System.out.println or System.out.printf method. (2 points)arrow_forwardWrite a program that reads a list of integers from input and determines if the list is a palindrome (values are identical from first to last and last to first). The input begins with an integer indicating the length of the list that follows. Assume the list will contain a maximum of 20 integers. Output "yes" if the list is a palindrome and "no" otherwise. The output ends with a newline. Hints: - use a for loop to populate the array based on the specified size (the first number entered) - use a for loop to check first value with last value, second value with second from end, etc. - if the values do not match, set a Boolean variable to flag which statement to output (yes or no) Ex: If the input is (remember to include spaces between the numbers): 6 1 5 9 9 5 1 the output is: yes Ex: If the input is: 5 1 2 3 4 5 the output is: C++ codingarrow_forwardDesign and draw a high-level "as-is" process diagram that illustrates a current process related to a product or service offered through the SSDCI.gov database.arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,Programming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage Learning




