
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!

Chapter 8 Solutions
Mindtap Computing, 1 Term (6 Months) Printed Access Card For Farrell’s Java Programming, 8th
- Explain Five reasons if computers should replace teachers. Provide three references with your answer. List three advantages and three disadvantages face to face learning and online learning may have on children. Provide two references with your answer.arrow_forwardYou were requested to design IP addresses for the following network using the address block 10.10.10.0/24. Specify an address and net mask for each network and router interfacearrow_forwardFor the following network, propose routing tables in each of the routers R1 to R5arrow_forward
- How can I type the Java OOP code by using JOptionPane with this following code below: public static void sellCruiseTicket(Cruise[] allCruises) { //Type the code here }arrow_forwardDraw a system/level-0 diagram for this scenario: You are developing a new customer relationship management system for the BEC store, which rents out movies to customers. Customers will provide comments on new products, and request rental extensions and new products, each of which will be stored into the system and used by the manager for purchasing movies, extra copies, etc. Each month, one employee of BEC will select their favorite movie pick of that week, which will be stored in the system. The actual inventory information will be stored in the Entertainment Tracker system, and would be retrieved by this new system as and when necessary. Example of what a level-0 diagram looks like is attached.arrow_forwardWhat is the value of performing exploratory data analysis in designing data visualizations? What are some examples?arrow_forward
- Draw a level-0 diagram for this scenario: You are developing a new customer relationship management system for the BEC store, which rents out movies to customers. Customers will provide comments on new products, and request rental extensions and new products, each of which will be stored into the system and used by the manager for purchasing movies, extra copies, etc. Each month, one employee of BEC will select their favorite movie pick of that week, which will be stored in the system. The actual inventory information will be stored in the Entertainment Tracker system, and would be retrieved by this new system as and when necessary.arrow_forwardDraw a context diagram for this scenario: You are developing a new customer relationship Management system for the BEC store, which rents out movies to customers. Customers will provide comments on new products, and request rental extensions and new products, each of which will be stored into the system and used by the manager for purchasing movies, extra copies, etc. Each month, one employee of BEC will select their favorite movie pick of that week, which will be stored in. the system. The actual inventory information will be stored in the Entertainment Tracker system, and would be retrieved by this new system as and when necessary.arrow_forwardWrite a complete Java program named FindSumAndAverage that performs the following tasks in 2-D array: Main Method: a. The main() method asks the user to provide the dimension n for a square matrix. A square matrix has an equal number of rows and columns. b. The main() method receives the value of n and calls the matrixSetUp() method that creates a square matrix of size n and populates it randomly with integers between 1 and 9. c. The main method then calls another method named printMatrix() to display the matrix in a matrix format. d. The main method also calls a method named findSumAndAverage() which: • Receives the generated matrix as input. • Calculates the sum of all elements in the matrix. • Calculates the average value of the elements in the matrix. • Stores these values (sum and average) in a single-dimensional array and returns this array • e. The main method prints the sum and average based on the result returned from findSumAndAverage()). Enter the dimension n for the square…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




