
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
- import tkint class ShowInfoGUI:def __init__(self):# Create the main windowself.main_window = tkinter.Tk() # Create two framesself.top_frame = tkinter.Frame(self.main_window)self.bottom_frame = tkinter.Frame(self.main_window)arrow_forwardJOB UPDATE Apply on- COMPANY VinkJobs.com @ OR Search "Vinkjobs.com" on Google JOB PROFILE JOB LOCATION INTELLIFLO APPLICATION DEVELOPER MULTIPLE CITIES GLOBAL LOGIC SOFTWARE ENGINEER/SDET DELHI NCR SWIGGY SOFTWARE DEVELOPMENT BENGALURU AVALARA SOFTWARE ENGINEER (WFH) MULTIPLE CITIES LENSKART FULL STACK DEVELOPER MULTIPLE CITIES ACCENTURE MEDPACE IT CUST SERVICE SOFTWARE ENGINEER MUMBAI MUMBAI GENPACT BUSINESS ANALYST DELHI NCR WELOCALIZE WORK FROM HOME MULTIPLE CITIES NTT DATA BPO ASSOCIATE DELHI NCRarrow_forwardHow can predictive and prescriptive modeling be used to measure operational performance in real-time? Do you see any potential downsides to this application? Can you provide an example?arrow_forward
- Tracing the Recursion. Tracing the Recursion. Observe the recursive solution provided below. 1. Which line(s) of this program define(s) the base case of sumOfDigits() method? 2. Which line(s) of this program include recursive call(s)? 3. Trace the recursion below. You must show the trace step by step; otherwise – little to no credit! 4. Show me the final result! 1 public class SumOfDigitsCalculator { 30 123456 7% 8 public static void main(String[] args) { System.out.println(sumOfDigits(1234)); } public static int sumOfDigits (int number) { if (number == 0) 9 10 11 12 } 13 } else return 0; return number % 10 + sumOfDigits (number / 10);arrow_forwardmodule : java 731 Question3: (30 MARKS) Passenger Rail Agency for South Africa Train Scheduling System Problem Statement Design and implement a train scheduling system for Prasa railway network. The system should handle the following functionalities: 1. Scheduling trains: Allow the addition of train schedules, ensuring that no two trains use the same platform at the same time at any station. 2. Dynamic updates: Enable adding new train schedules and canceling existing ones. 3. Real-time simulation: Use multithreading to simulate the operation of trains (e.g., arriving, departing). 4. Data management: Use ArrayList to manage train schedules and platform assignments. Requirements 1. Add Train Schedule, Cancel Scheduled Train, View Train Schedules and Platform Management 2. Concurrency Handling with Multithreading i.e Use threads to simulate train operations,…arrow_forwardplease answer my 2 java questions correctly , include all comments etc and layout and structure must be correct , follow the requirementsarrow_forward
- Question3: Passenger Rail Agency for South Africa Train Scheduling System Problem Statement (30 MARKS) Design and implement a train scheduling system for Prasa railway network. The system should handle the following functionalities: 1. Scheduling trains: Allow the addition of train schedules, ensuring that no two trains use the same platform at the same time at any station. 2. Dynamic updates: Enable adding new train schedules and canceling existing ones. 3. Real-time simulation: Use multithreading to simulate the operation of trains (e.g., arriving, departing). 4. Data management: Use ArrayList to manage train schedules and platform assignments. Requirements 1. Add Train Schedule, Cancel Scheduled Train, View Train Schedules and Platform Management 2. Concurrency Handling with Multithreading i.e Use threads to simulate train operations, Each train runs as a separate thread, simulating its arrival, departure, and travel status. 3. Use ArrayList to manage train schedules for each…arrow_forwardplease answer my java question correctly , include all comments etc and layout and structure must be correct , follow the requirementsarrow_forwardplease answer my java question correctly , include all comments etc and layout and structure must be correct , follow the requirementsarrow_forward
- please answer my java question correctly , follow all requirements , add all commets etc and layout and structure must be perfect tooarrow_forwardplease answer my java question correctly , include all comments etc and layout and structure must be correct , follow the requirementsarrow_forward7. Long-Distance CallsA long-distance provider charges the following rates for telephone calls: Rate Category Rate per MinuteDaytime (6:00 a.m. through 5:59 p.m.) $0.07Evening (6:00 p.m. through 11:59 p.m.) $0.12Off-Peak (midnight through 5:59 a.m.) $0.05Write a GUI application that allows the user to select a rate category (from a set of radio buttons), and enter the number of minutes of the call into an Entry widget. An info dialog box should display the charge for the call.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




