Question 1 Write a Java program containing the static methods described in the following paragraphs. You...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Question 1 Write a Java program containing the static methods described in the following paragraphs. You need not include exception handling and validation in your solution. You must not use the following in your solution: • • • • Lambda expression The Stream API Methods in the Arrays class (java.util.Arrays) Methods in the Collections class (java.util.Collections) Method 1 public static void printNumbers (int startNum, int endNum, int numPerLine) { // Your code } The method will print numbers from startNum to endNum, inclusive of both ends. The method will print numPerLine numbers per line. Example 1: printNumbers (21, 29, 4) will produce the following: 21 22 23 24 25 26 27 28 29 Example 2: print Numbers (4, 12, 6) will produce the following: 4 5 6 7 8 9 10 11 12 You may assume: • startNum >= 0, numPerLine > 0 startNum < endNum You must not use int [ ] or ArrayList in your solution. Method 2 public static boolean has DuplicateChars (String data) { } // Your code The method will return true if there are duplicate characters in data and false otherwise. Examples: has DuplicateChars ("abcala2") will produce true. has DuplicateChars ("morning") will produce true. hasDuplicateChars("ab$wx$y") will produce true. has DuplicateChars ("35 x 12") will produce true. (2 blank spaces) has DuplicateChars ("methods") will produce false. You may assume the letters: a, b, c ... z are in lower case. You must not use char () or ArrayList in your solution. Method 3 public static String replaceWith (String data, // Your code char chl, char ch2) { The method will return an instance of String containing all characters in data but with all occurrences of ch1 replaced by ch2. You must use recursion. Examples: replaceWith("programming", 'r' 'R'); replaceWith("java", 'a', 'A'); replaceWith("1+2×3+4", '+' '%'); ') Return value "pRogRamming" "jAVA". "1%2x3%4". "22-Jun-2022" replace With ("22 Jun 2022" You must not use char[] or ArrayList in your solution. Method 4 public static int countDigit (int number, int digit) { } // Your code The method will count and return the number of occurrences of digit within number. You must use recursion. Examples: count Digit (5, 0); count Digit (1, 1); countDigit (12257212, 2); countDigit (51299189, 9) You may assume: • number 0 • digit is 0 - 9 You must not use char[] or ArrayList in your solution. Return value 0 1 4 3 Program Structure You may include additional variables and methods as you deem fit. public class Question1 { public static void main(String[] argv) { } // Add statements to call and test the various methods. // The statements in this method will NOT be graded. } public static void print Numbers (int startNum, int endNum, int numPerLine) { // Your code } public static boolean has DuplicateChars (String data) { // Your code } public static String replaceWith (String data, // Your code } char ch1, char ch2) { public static int countDigit (int number, int digit) { // Your code Question 1 Write a Java program containing the static methods described in the following paragraphs. You need not include exception handling and validation in your solution. You must not use the following in your solution: • • • • Lambda expression The Stream API Methods in the Arrays class (java.util.Arrays) Methods in the Collections class (java.util.Collections) Method 1 public static void printNumbers (int startNum, int endNum, int numPerLine) { // Your code } The method will print numbers from startNum to endNum, inclusive of both ends. The method will print numPerLine numbers per line. Example 1: printNumbers (21, 29, 4) will produce the following: 21 22 23 24 25 26 27 28 29 Example 2: print Numbers (4, 12, 6) will produce the following: 4 5 6 7 8 9 10 11 12 You may assume: • startNum >= 0, numPerLine > 0 startNum < endNum You must not use int [ ] or ArrayList in your solution. Method 2 public static boolean has DuplicateChars (String data) { } // Your code The method will return true if there are duplicate characters in data and false otherwise. Examples: has DuplicateChars ("abcala2") will produce true. has DuplicateChars ("morning") will produce true. hasDuplicateChars("ab$wx$y") will produce true. has DuplicateChars ("35 x 12") will produce true. (2 blank spaces) has DuplicateChars ("methods") will produce false. You may assume the letters: a, b, c ... z are in lower case. You must not use char () or ArrayList in your solution. Method 3 public static String replaceWith (String data, // Your code char chl, char ch2) { The method will return an instance of String containing all characters in data but with all occurrences of ch1 replaced by ch2. You must use recursion. Examples: replaceWith("programming", 'r' 'R'); replaceWith("java", 'a', 'A'); replaceWith("1+2×3+4", '+' '%'); ') Return value "pRogRamming" "jAVA". "1%2x3%4". "22-Jun-2022" replace With ("22 Jun 2022" You must not use char[] or ArrayList in your solution. Method 4 public static int countDigit (int number, int digit) { } // Your code The method will count and return the number of occurrences of digit within number. You must use recursion. Examples: count Digit (5, 0); count Digit (1, 1); countDigit (12257212, 2); countDigit (51299189, 9) You may assume: • number 0 • digit is 0 - 9 You must not use char[] or ArrayList in your solution. Return value 0 1 4 3 Program Structure You may include additional variables and methods as you deem fit. public class Question1 { public static void main(String[] argv) { } // Add statements to call and test the various methods. // The statements in this method will NOT be graded. } public static void print Numbers (int startNum, int endNum, int numPerLine) { // Your code } public static boolean has DuplicateChars (String data) { // Your code } public static String replaceWith (String data, // Your code } char ch1, char ch2) { public static int countDigit (int number, int digit) { // Your code
Expert Answer:
Answer rating: 100% (QA)
Java public class StringUtil public static void printNumb... View the full answer
Related Book For
Java An Introduction To Problem Solving And Programming
ISBN: 9780134462035
8th Edition
Authors: Walter Savitch
Posted Date:
Students also viewed these programming questions
-
The Taylor polynomial for sin(x) for a near 0 to order 5 is 1 1 sin(x) = x - + -x +0(x7) 6 120 The figure below shows a plot of sin(x) [blue] and the above Taylor polynomial [red]. 0.8 0.6 0.4 0.2 1...
-
For each polynomial function, find (a) (-1), (b) (2), and (c) (0). f(x) = x + 5x
-
As of December 31, 2017, Colt Corporation has a loss carryforward of $180,000 available to offset future taxable income. At December 31, 2017, the company believes that realization of the tax benefit...
-
The density function of the random variable X is given by Find P(X < 1/4 ) and P(X > 1/2). 6x( 1-r) 1 for 0
-
A \(6.0-\mathrm{kg}\) bowling ball is held \(10 \mathrm{~mm}\) above a mattress and then released from rest and allowed to fall, sinking into the mattress. Model the mattress as a single spring with...
-
An industry consists of three firms with sales of $200,000, $500,000, and $400,000. a. Calculate the Herfindahl-Hirschman index (HHI). b. Calculate the four-firm concentration ratio (C4). c. Based on...
-
The following transactions occurred for the Microchip Company. 1. On October 1, 2024, Microchip lent $81,000 to another company. A note was signed with principal and 8% interest to be paid on...
-
A shaft is to be designed to support the spur pinion and helical gear shown in the figure on two bearings spaced 700 mm center-to-center. Bearing A is a cylindrical roller and is to take only radial...
-
What is the concentration (M) of lithium ions in 4.57 L of a 2.35 M Li3P solution? 45.0 M O 14.1 M O 2.35 M 7.05 M 99.0 M Submit My Answers Give Up
-
Explain the physical changes that occur in sexuality in men and women during middle adulthood.
-
1 ) Describe the key differences between equity and debt 2 ) What is preferred stock? 3 ) Describe the concept of Market Efficiency?
-
3. Six months ago, Warren entered into a SHORT position in a one-year forward for 100 shares of stock of Erkis Industries at a forward price of $25 per share. Erkis Industries stock paid a dividend...
-
1) Fill in the blanks with either "positively" or "negatively" a) interest rates are b) the value of the dollar is c) interest rates are d) government spending is e) consumer confidence is [5]...
-
What are the positive and negative implications of Parsons four-problem matrix? Please provide at least one positive implication and one negative implication.
-
Congratulations! Your team has just won the Basketball State finals. The 6 points you scored helped clinch the victory. On the long bus ride home, you'd like to get some sleep. Before you can doze...
-
Why is it necessary to study the diffusion of molecules in biological systems?
-
Write a program that reads records of type Pet from a file created by the program described in the previous programming project and displays the following information on the screen: the name and...
-
Consider a Java class that you could use to get an acceptable integer value from the user. An object of this class will have the attributes Minimum accepted value Maximum accepted value Prompt string...
-
Write a program that uses the class Calculator in Listing 9.12 to create a more powerful calculator. This calculator will allow you to save one result in memory and call the result back. The commands...
-
For each of the following studies, identify the type of graph (histogram, time series graph, or scatter diagram) that would be the most appropriate. (You can use more than one graph of each type, for...
-
For each of the following studies, identify the type of graph (histogram, time series graph, or scatter diagram) that would be the most appropriate. (You can use more than one graph of each type, for...
-
Use the data in Table 1.4 to make a histogram of the U.S. dollar prices of a Big Mac in these 20 countries. Use these intervals for the prices: 12, 23, 34, 45, 58. United States Argentina Australia...
Study smarter with the SolutionInn App