Activity : Start with method DoubleIt. Delete the throw statement. Brainstorm th
ID: 645113 • Letter: A
Question
Activity: Start with method DoubleIt.
Delete the throw statement.
Brainstorm the solution to the method with a lab partner. (If you prefer, you may work alone.)
Fill in the method code block with your solution.
Recompile your program.
Run your program to see if your method works.
If not, debug as needed until your get the correct result.
When the DoubleIt method works perfectly, repeat the process for the second method.
When the second method works perfectly, repeat the process for the third method and so on, until all are complete.
Click here for the API of the methods that you will be writing.
/**
* Takes a numeric parameter and returns the value times two.
*
* @param value the value to be doubled
*
* @return the parameter doubled
*/
public static double doubleIt(double value)
{
throw new UnsupportedOperationException("Method not yet implmented..");
// calculate and return the parameter times two.
}
/**
* Prints a user supplied message the number of times specified by the parameter.
* @param message the message to be printed
* @param count the number of times to print the message
*
*/
public static void messagePrint(String message, int count)
{
throw new UnsupportedOperationException("Method not yet implmented..");
// print message, count times
}
/**
* returns a code for a word
* @param word for which the code is to be obtained
* @return a code for a word calculated by summing the integer values of each character
*
*/
public static String getCode(String word)
{
throw new UnsupportedOperationException("Method not yet implmented..");
// initialize the secret code String to the empty String ""
// set up a for loop that will iterate through the characters of parameter word
// and append the integer value for each character to the secret code
// return the resulting String
}
/**
* returns a random integer value from within the specified range, inclusively
* @param lb the lower boundary of the range
* @param ub the upper boundary of the range
* @return a number between lb and ub inclusively
*/
public static int getRandom(int lb, int ub)
{
throw new UnsupportedOperationException("Method not yet implmented..");
// instantiate a Random number generator named gen
// calculate a random number from lb to ub:
//int ran = gen.______________(ub-lb+1) + lb;
// return the result
}
/**
* returns the characters of the parameter in reverse order
* @param word to be reversed
* @return the reverse order version of word
*/
public static String reverse (String word)
{
throw new UnsupportedOperationException("Method not yet implmented..");
// initialize a String reference for the reversed word to the empty String
//String reverse = "";
// write a reverse for loop that appends each character of word to the String
}
/**
* @param number to be tested
* @return true if the number is even and false otherwise.
*/
public static boolean isEven(int number)
{
throw new UnsupportedOperationException("Method not yet implmented..");
// write an if-else statement that will return true if number is even and false otherwise.
}
}
Activity: Start with method DoubleIt. Delete the throw statement. Brainstorm the solution to the method with a lab partner. (If you prefer, you may work alone.) Fill in the method code block with your solution. Recompile your program. Run your program to see if your method works. If not, debug as needed until your get the correct result. When the DoubleIt method works perfectly, repeat the process for the second method. When the second method works perfectly, repeat the process for the third method and so on, until all are complete. Click here for the API of the methods that you will be writing.Explanation / Answer
import java.util.Random;
public class test{
/**
* Takes a numeric parameter and returns the value times two.
*
* @param value the value to be doubled
*
* @return the parameter doubled
*/
public static double doubleIt(double value)
{
return 2.0 * value;
}
/**
* Prints a user supplied message the number of times specified by the parameter.
* @param message the message to be printed
* @param count the number of times to print the message
*
*/
public static void messagePrint(String message, int count)
{
int times;
for(int i = 1; i <= count; i++){
System.out.println(message);
}
// print message, count times
}
/**
* returns a code for a word
* @param word for which the code is to be obtained
* @return a code for a word calculated by summing the integer values of each character
*
*/
public static String getCode(String word)
{
String secretCode = "";
for(int i = 0; i < word.length(); i++){
secretCode += (int)(word.charAt(i));
}
return secretCode;
// initialize the secret code String to the empty String ""
// set up a for loop that will iterate through the characters of parameter word
// and append the integer value for each character to the secret code
// return the resulting String
}
/**
* returns a random integer value from within the specified range, inclusively
* @param lb the lower boundary of the range
* @param ub the upper boundary of the range
* @return a number between lb and ub inclusively
*/
public static int getRandom(int lb, int ub)
{
Random r = new Random();
int temp = lb + (ub - lb + 1);
return temp;
// instantiate a Random number generator named gen
// calculate a random number from lb to ub:
//int ran = gen.______________(ub-lb+1) + lb;
// return the result
}
/**
* returns the characters of the parameter in reverse order
* @param word to be reversed
* @return the reverse order version of word
*/
public static String reverse (String word)
{
String reverse = "";
for(int i = word.length() - 1; i >= 0; i--){
reverse += word.charAt(i);
}
return reverse;
// initialize a String reference for the reversed word to the empty String
//String reverse = "";
// write a reverse for loop that appends each character of word to the String
}
/**
* @param number to be tested
* @return true if the number is even and false otherwise.
*/
public static boolean isEven(int number)
{
if(number % 2 == 0) return true;
else return false;
// write an if-else statement that will return true if number is even and false otherwise.
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.