ackage minil; _mport java.util.Scanner; ** * Utility class with some static methods involving loops. */ ublic...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
ackage minil; _mport java.util.Scanner; ** * Utility class with some static methods involving loops. */ ublic class WackyLoops{ /** * Determines how many iterations of the following operation are required until * the condition (a* a + b*b) > 4 is reached: * * *newA = a*ab*b+x * newB * * * newB = 2 *a*b+y a = newA b = newB * * where a and b are initially zero. If the condition (a*a+b*b) > 4 is *not reached within maxIterations , the method returns * maxIterations . * * @param x given x value * @param y given y value * @param maxIterations maximum number of iterations to attempt * @return number of iterations required to get (a a+b*b) > 4, or maxIterations * */ public static int findEscapeCount (double x, double y, int maxIterations) { } /** * Counts the number of positions in a pair of strings that have matching * characters. The strings need not be the same length. For example, *countMatches ("abcde", "xbydzzzzz") returns 2. * * @param s any string * @param t any string * @return number of positions in which the characters match in the two strings */ public static int countMatches (String s, String t) { } /** * Determines whether the two given strings are permutations (rearrangements) of * each other. The method is case sensitive. For example, * * isPermutation ("abcabc", "baaccb") returns true * isPermutation ("abc", "cbba") returns false * isPermutation ("Abc", "abc") returns false * * * @param s given string * @param t given string * @return true if the given strings are permutations of each other, false otherwise */ PARIS ELFI M MA public static boolean is Permutation (String s, String t) { } /*** *Returns a new string in which all consonants in the given string are doubled. *Consonants that are already doubled are not doubled again. For example, * doubleConsonants ("rabbit") returns "rrabbitt". It is assumed that in the *given string is alphabetic and that no character appears more than twice in a * row. *. * @param s given string * @return new string with all consonants doubled .*/ public static String doubleConsonants (String s) { } private static boolean is Vowel(char ch) { return "aeiouAEIOU".indexOf(ch) >= 0; } * Returns the second largest number in a string of integers. For example, given *the string "42 137 7 42 66 55" the method returns 66. Note that the second * largest value may be the same as the largest, e.g., for the string "5.5.5.3" * the method returns 5. If the given string is invalid or contains fewer than * two numbers, the behavior of this method is undefined. *. * @param nums string of text containing integers separated by one or more *********** spaces * * @return second largest number in the given string */ public static int find Second Largest(String nums) { } /** * Determines whether the string target occurs as a substring of * string source where "gaps" are allowed between characters of * target . That is, the characters in target occur in * source in their given order but do not have to be adjacent. * (Pictured another way, this method returns true if target could * be obtained from source by removing some of the letters of * source .) This method is case sensitive. For example, * * containsWithGaps ("hamburgers", "mug") returns true * containsWith Gaps ("hamburgers", "burrs") returns true * containsWithGaps ("hamburgers", "hamburgers") returns true * containsWithGaps (" hamburgers", "gum") returns false * containsWith Gaps ("hamburgers", "hamm") returns false * containsWithGaps ("hamburgers","") returns true * * * @param source the given string in which to find the target characters * @param target the characters to be found * @return true if the characters in target can be found as a subsequence in source , false otherwise * .*/ public static boolean substringWith Gaps (String source, String target) { } If you are working on findSecondLargest, can you a. Parse a given string into a sequence of integers. Numbers in a String can be scanned via java.util.Scanner and obtained through the nextInt API one at a time. For example: String nums = "12 34 -56 77 0"; Scanner in = new Scanner (nums); int num1 = in.nextInt(); // 12 int num2 = in.nextInt (); // 34 Return the largest number in a string of integers Return the second largest number in a string of integers. Consider whether additional variables need to be employed. If you are working on substringWithGaps, can you b. a. Return the index of the first char in the source string that matches a given target char. Loop through the chars in the target string. Use each of the chars as a target for the problem above. c. Do the same. But instead of checking the source string from the beginning, start from an char that one position over the one that matches the previous target character. d. Return false if no matching character is found by the end of the source string. Otherwise, return true. b. c. ackage minil; _mport java.util.Scanner; ** * Utility class with some static methods involving loops. */ ublic class WackyLoops{ /** * Determines how many iterations of the following operation are required until * the condition (a* a + b*b) > 4 is reached: * * *newA = a*ab*b+x * newB * * * newB = 2 *a*b+y a = newA b = newB * * where a and b are initially zero. If the condition (a*a+b*b) > 4 is *not reached within maxIterations , the method returns * maxIterations . * * @param x given x value * @param y given y value * @param maxIterations maximum number of iterations to attempt * @return number of iterations required to get (a a+b*b) > 4, or maxIterations * */ public static int findEscapeCount (double x, double y, int maxIterations) { } /** * Counts the number of positions in a pair of strings that have matching * characters. The strings need not be the same length. For example, *countMatches ("abcde", "xbydzzzzz") returns 2. * * @param s any string * @param t any string * @return number of positions in which the characters match in the two strings */ public static int countMatches (String s, String t) { } /** * Determines whether the two given strings are permutations (rearrangements) of * each other. The method is case sensitive. For example, * * isPermutation ("abcabc", "baaccb") returns true * isPermutation ("abc", "cbba") returns false * isPermutation ("Abc", "abc") returns false * * * @param s given string * @param t given string * @return true if the given strings are permutations of each other, false otherwise */ PARIS ELFI M MA public static boolean is Permutation (String s, String t) { } /*** *Returns a new string in which all consonants in the given string are doubled. *Consonants that are already doubled are not doubled again. For example, * doubleConsonants ("rabbit") returns "rrabbitt". It is assumed that in the *given string is alphabetic and that no character appears more than twice in a * row. *. * @param s given string * @return new string with all consonants doubled .*/ public static String doubleConsonants (String s) { } private static boolean is Vowel(char ch) { return "aeiouAEIOU".indexOf(ch) >= 0; } * Returns the second largest number in a string of integers. For example, given *the string "42 137 7 42 66 55" the method returns 66. Note that the second * largest value may be the same as the largest, e.g., for the string "5.5.5.3" * the method returns 5. If the given string is invalid or contains fewer than * two numbers, the behavior of this method is undefined. *. * @param nums string of text containing integers separated by one or more *********** spaces * * @return second largest number in the given string */ public static int find Second Largest(String nums) { } /** * Determines whether the string target occurs as a substring of * string source where "gaps" are allowed between characters of * target . That is, the characters in target occur in * source in their given order but do not have to be adjacent. * (Pictured another way, this method returns true if target could * be obtained from source by removing some of the letters of * source .) This method is case sensitive. For example, * * containsWithGaps ("hamburgers", "mug") returns true * containsWith Gaps ("hamburgers", "burrs") returns true * containsWithGaps ("hamburgers", "hamburgers") returns true * containsWithGaps (" hamburgers", "gum") returns false * containsWith Gaps ("hamburgers", "hamm") returns false * containsWithGaps ("hamburgers","") returns true * * * @param source the given string in which to find the target characters * @param target the characters to be found * @return true if the characters in target can be found as a subsequence in source , false otherwise * .*/ public static boolean substringWith Gaps (String source, String target) { } If you are working on findSecondLargest, can you a. Parse a given string into a sequence of integers. Numbers in a String can be scanned via java.util.Scanner and obtained through the nextInt API one at a time. For example: String nums = "12 34 -56 77 0"; Scanner in = new Scanner (nums); int num1 = in.nextInt(); // 12 int num2 = in.nextInt (); // 34 Return the largest number in a string of integers Return the second largest number in a string of integers. Consider whether additional variables need to be employed. If you are working on substringWithGaps, can you b. a. Return the index of the first char in the source string that matches a given target char. Loop through the chars in the target string. Use each of the chars as a target for the problem above. c. Do the same. But instead of checking the source string from the beginning, start from an char that one position over the one that matches the previous target character. d. Return false if no matching character is found by the end of the source string. Otherwise, return true. b. c.
Expert Answer:
Related Book For
Numerical Methods With Chemical Engineering Applications
ISBN: 9781107135116
1st Edition
Authors: Kevin D. Dorfman, Prodromos Daoutidis
Posted Date:
Students also viewed these programming questions
-
In this question you will be asked to reflect on a project you have been involved in or observed, in which a design evolved, or could have evolved, through applying a theory of user behaviour. You...
-
In a Hopfield neural network configured as an associative memory, with all of its weights trained and fixed, what three possible behaviours may occur over time in configuration space as the net...
-
1. What is the present value (PV") of an offer of $15,000 two years from now if the Opportunity Cost of Capital (OCC) is $12% per annum? 2. What is the PV of an offer to receive $12,000 three years...
-
Refer to the information regarding Martin Towing Company in P4-3. Required: 1. Indicate whether each transaction relates to a deferred revenue, deferred expense, accrued revenue, or accrued expense....
-
Vidriera Monterrey is analyzing a proposal from a new client to purchase its engraved vases for $75.00. The Commercial Director has asked us for support in making this decision and provides us with...
-
Redwing Floor Coverings, Inc., reported the following summarized data at December 31, 2009. Accounts appear in no particular order. Requirement 1. Prepare the trial balance of Redwing Floor Coverings...
-
A financial analyst engaged in business valuation obtained financial data on 53 drug companies (Industry Group SIC 3 code: 283). The file Business Valuation contains the following variables: COMPANY...
-
Set I Q. Harish Aggarwal, a management accountant with the Maruti Udyog, is evaluating whether a component MTR.2000 should continue to be manufactured by Maruti or purchased from Outside Vendor...
-
Bamboo Consulting is a consulting firm owned and operated by Lisa Gooch. The following end-of-period spreadsheet was prepared for the year ended July 31, 2016: Based on the preceding spreadsheet,...
-
The firms managers decide to use 5 workers and 2 pieces of capital to produce the optimal level of output for the firm. Suppose that optimal level of output is 100 units and that the rental cost of...
-
what ways does emotional intelligence among leaders correlate with organizational success, and how can organizations develop and leverage emotional intelligence within their leadership teams ?
-
If you borrow $ 3 , 000 on an 8 % discounted loan for 9 months, how much will you actually receive?
-
A company issued 2,000,000$,12%, 5 years semianually bonds when the bonds yield 10% at 1/1/2022. In 30/06/2024 after payment of interest the company decided to retire half of the bonds for...
-
5. What radical expression could be added to -3/45+2/12+327-3/20 to obtain a sum of 500+300? Write each term as a mixed radical in simplest form to begin. (4 marks)
-
What role does emotional intelligence play in conflict resolution, and how can higher levels of emotional intelligence improve outcomes in contentious situations ?
-
1. 2. 3. Write the function called fn_speedconv which converts the wind speed from mph to Knots and km/h. 1 Knots = 1.152 mph 1 mph = 1.609 km/h The Beaufort Wind Scale (see table. 1)is used to...
-
What are conversion costs? What are prime costs?
-
We saw that the time t required to solve a banded matrix of size n n with a bandwidth p = q scales like t np 2 . In this problem, we will explore the ability of MATLABs internal solver to handle...
-
Use a linear stability analysis to determine the maximum step size that you could use for the forward Euler integration of the differential equation y + 2(y)2 y = 0 as a function of the local slope,...
-
Solve the system by Jacobis method with an initial guess (0, 0). 2x1 + x = 2 x12x = -2 (2.13.7)
-
If share rights are recognized on issuance, what happens to the share rights account if the share rights are exercised? Allowed to lapse? Compare this to the treatment of the common share conversion...
-
When would a share-based compensation contract, payable after three years, result in an equity account being recognized in the first year? A liability? Both equity and a liability?
-
Assume that a cash-settled share-based payment scheme is established for an employee group. It will vest over five years, and be paid at the end of the fifth year. The total fair value of the plan is...
Study smarter with the SolutionInn App