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
JAVA PROGRAM(LL)+MINDTAP (1 TERM) V2.0
- Create a program that stores the names of the user's friends in a list. The program should allow a user to add friends to the list, remove friends from the list, and display the entire list of friends. A menu should be created that displays those options like so: 1 - View all 2 - Add Friend 3 - Remove Friend 4 - Exit The program should continue in a loop until the user selects exit. Hint: Use a function for each menu selection.arrow_forwardPython Previously, your check_move function took two separate arguments: a column and a row value. Now you will rewrite the function to accept the board position as a single string argument. In other words, write check_move (position) which takes position strings such as '85" that include both the column and the row value of a chess board. • When both the coordinates in position are valid, for example, "c4", the function returns 'The piece is moved to C4.'. • If position has too many or too few characters, return 'The position is not valid.' • If the first coordinate is out of range (regardless of whether the second one is or not) return 'The column value is not in the range a-h or A-HI¹. . Otherwise, if the second coordinate is out of range, return 'The row value is not in the range 1 to 81¹. Note that, irrespective of the casing of the column value, your code should output the value in upper case. Your function should work like this: >>> check_move('B4') 'The piece is moved to B4.'…arrow_forward7. The following function converts a postfix expression to an infix expression assuming the expression can only contain unsigned integer numbers and +' and -' operators. 1. public static String convert (String postfix) { 2. String operand1, operand2, infix; 3. Stack s = new AStack; 4. int i = 0; 5. while (i < postfix.length) { char nextc = postfix.charAt (i); if ((nextc 6. 7. '+')|| (nextc == '-') { == operand2 = s.pop (); operandl = s.pop () ; infix = '(' + operandl + nextc + operand2 + ')'; s.push (infix); i++; 8. 9. 10. 11. } 12. else if (Character.isDigit (nextc)){ int start = i; while (Character.isDigit (postfix.charAt (i)) i++; infix = postfix.substring (start, i); s.push (infix); 13. 14. 15. 16. 17. } else i++; 18. 19. } 20 return s.pop () ; 21. } (a) Rewrite only the lines of code that need to be changed so that the above function converts a postfix expression to a prefix expression. (b) Describe in words what changes are needed on the above given convert () function so that it…arrow_forward
- ///-In python-/// def get_words_last_1():"""The function should take a list of wordsas an input parameter and return a new list of stringswith the last character removed. (Use string slicing)If the word is empty or has only 1 character, then skip it.""" pass The code should aslo have if __name__ == "__main__" section.arrow_forwardCreate a Python application that makes use of inputs, outputs, and sequence structures in Python. It must meet all of the following requirements: The application must create a list with exactly 10 items. The contents and type of list will be up to the student (e.g. Phone Brands, Types of Shoes, Shopping Apps). The application must first display the list after which the application must remove 5 random items from the list. The application must then show the updated list with 5 of the items removed. After this is done, the application must add 7 new items to the list. These items must be completely new and not the ones that were on the list initially. The application must then output the updated list with the added items. The application must then reverse the list and then display the updated list after it has been reversed. The application must create a tuple with exactly 10 items. The contents and type of tuple will be up to the student (e.g. Laptop Brands, Types of Pants, Game Apps).…arrow_forward3. Complete the function count_digits. This function takes one parameter - a string (s). It should return the number of digits in s. For example, if s is "25 or 6 to 4 is a song by Chicago" then count_digits should return 4. count_digits should not print the result- it should return it. Do not change anything outside count_digits. Save & Run Load History Show CodeLens 1 def count_digits(s): 2 ''Returns the number of digits in s''" 3 pass #Hint: make a string of digits to use #in checking whether each character #is a digit. And use the accumulator #pattern 4 6. 7 8. 9 user_string 10 num_digits 11 print("There are", num_digits, "digits in", user_string) input("Please enter a string: ") count_digits(user_string) 12arrow_forward
- Q1. With Menu Driven Program Design a Calculator having all the main functions also use Math's functions. Q2. Write a program to find that a letter is vowel or not using If-else statement? Q3. Write a program that performs a survey on beverages. The program sholud prompt for the next person untila lookout value of -1 is entered to terminate the program. Each person participating in the survey should choose their favorite beverage from the following list? 1. Cofee 2. Tea 3. Coke 4. Orange Juice Q4. Given an integer n such as 1367. Write a program that computes the inverse of this integer as 7631. Q5. Write a program to print prime numbers within given range using while loop?arrow_forwardJAVA PROGRAM THIS PROGRAM MUST WORK IN HYPERGRADE. The output should DISPLAY the following: Enter a name to search or type QUIT to exit:\n And then I type Anabelle AND PRESS ENTER and print out this: The name 'Annabelle' was not found in either list.\n And then repeat Enter a name to search or type QUIT to exit:\n AND THEN I TYPE xavier and press enter and print out The name 'Xavier' was found in popular boy names list (line 81).\n Then repeat Enter a name to search or type QUIT to exit:\n and then I type AMANDA and press enter and print out The name 'Amanda' was found in popular girl names list (line 63).\n then repeat Enter a name to search or type QUIT to exit:\n then I type jOrdAn and press enter and print out The name 'Jordan' was found in both lists: boy names (line 38) and girl names (line 75).\n then repeat Enter a name to search or type QUIT to exit:\n and then I type quit and press enter to end the program. I HAVE PROVODED THE SCREENSHODE OF THE TEXTFILES AND THE TEST…arrow_forwardPlease do this in C# (C Sharp) Kilogram Converter In a medical office, employees must use weight measurements in kilograms and pounds. Create a program (console based ) that displays a table of kilograms 0-20 and the equivalent weight in pounds. The application should use a loop to display weights in a list box. Use this conversion: 1 kg = 2.2 lbs Calculating Factorials The notation n! represents to the factorial of the nonnegative integer n. The factorial of n is the product of all the nonnegative integers from 1 through n. For example, 3! = 1 x 2 x 3 = 6 9! = 1 x 2 x 3 x 4 x 5 x 6 x 7 x 8 x 9 = 362,880 Create a program (console based ) that lets the user enter a nonnegative integer and then uses a loop to calculate the factorial of that number. Display the factorial on a label or in a message box.arrow_forward
- In C programming language Question (Strings) Write a function find_Substring() that finds a substring into a string. Pass array s1 and s2 to this function and prints if the substring is present or not. Expected Output 1: Enter string This is a javascript Enter substring script The substring is present Expected Output 2: Enter string This is a javascript Enter substring Jscript The substring is not presentarrow_forwardDec2Hex function : def dec_to_hex(decimal): hex_digits = "0123456789ABCDEF" hex_string = "" while decimal > 0: hex_digit = decimal % 16 hex_string = hex_digits[hex_digit] + hex_string decimal = decimal // 16 # Pad the hexadecimal string with zeroes to make it a multiple of 2 bytes hex_string = hex_string.rjust((len(hex_string) + 1) // 2 * 2, "0") # Convert the hexadecimal string to bytes hex_bytes = bytes.fromhex(hex_string) return hex_bytes Add unit-testing code to your Dec2Hex exercise, and then perform aUnit test of the updated Dec2Hex code. Perform a Profile of your Dec2Hex function. Write a function that takes a timedate object as a parameter andcalculates the number of years from NOW to the time in the timedateobject.arrow_forwardin c language Write a program which performs the following actions: Write the header of the C program Write the beginning of the main function Initialize a string called first_string with the constant value "C programming is nice**" using a string pointers Initialize a string called second_string with the constant value "C language is difficult" using a string pointer Display first_string and second_string in two consecutive lines Display a message that shows if the two strings have the same length (hint: use sizeof). Assume now that both strings have the same size. Write only three statements to swap the two strings’ contents (swap means the content of the first string becomes the content of the second string and vice-versa) Display again the two strings to check whether they have been swapped Write the correct symbol to close the main functionarrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT