Question
Complete the JUnit Assignment so the code is properly functioning ______________________________________________________ public class JU09V { /** * This method accepts a number as parameter and
Complete the JUnit Assignment so the code is properly functioning
______________________________________________________
public class JU09V {
/**
* This method accepts a number as parameter and then creates
* a sentence in the form of "The square root of 100 is 10.0"
* @param number >= 0
* @return
*/
public static String squareRootSentence(int number) {
String response = "";
double squareRoot = Math.sqrt(number);//get the square root
response = "The square root of "+number+" is "+String.format("%.1f",squareRoot);
return response;
}
/**
* This method accepts a number as parameter and then creates
* a sentence in the form of "9 ^ 2 == 81"
* @param base
* @param exponent
* @return
*/
public static String exponentSentence(int base,int exponent) {
String response = "";
//calculate the value and convert it to long
long value = (long)Math.pow(base, exponent);
response = base+" ^ "+exponent+ " == "+value;//create the response
return response;
}
/**
* The method builds a sentence with the name and phrase
* the person shouts. shout("Grace","Java") -> Grace loves to shout the phase "Java"!
* @param name
* @param phrase
* @return
*/
public static String shout(String name,String phrase) {
return name+" loves to shout the phase "+"\""+phrase+"\"!";
}
/**
* Builds a computer filepath given the drive letter, mainFolder and the filename.
* @param driveLetter
* @param mainFolder
* @param fileName
* @return
*/
public static String getFilePath(String driveLetter,String mainFolder,String fileName) {
return driveLetter+":\\"+mainFolder+"\\"+fileName;
}
/**
* epicSqrt method will return squareroot of both positive and negative integer
* @param value
* @return
*/
public static String epicSqrt(int value) {
int value1 = value;
if(value1 < 0)
value1 = (-1)*value1;//get absolute value if number is negative
double sqrt = Math.sqrt(value1);//get square root of value1
String response = "Square root of "+value+" is "+
String.format("%.1f", sqrt)+(value<0?"i":"");//add i at end if value id negative
return response;
}
/**
* Given 2 Stirngs word1 and word2, concatenate them except theor first letters
* @param word1
* @param word2
* @return
*/
public static String noFirstLetterConcat(String word1,String word2) {
return word1.substring(1).concat(word2.substring(1));
}
/**
* This method will return a Stirng that displays first position of the vowels a,e,i,o,u
* in the given sentence.
* @param sentence
* @return
*/
public static String findVowels(String sentence) {
char[] vowels = {'a','e','i','o','u'};//declare array of vowels
String sentInLower = sentence.toLowerCase();//convert sentence in lowercase
String response = "";
for(char currentVowel: vowels) {//for each vowel
int index = sentInLower.indexOf(currentVowel);//find the first occurance in sentInLower
response = response+"The first position of "+currentVowel+" is "+index+" ";//create sentence for this vowel
}
return response;
}
//Main method to test methods
public static void main(String[] args) {
System.out.println(squareRootSentence(100));
System.out.println(exponentSentence(9,2));
System.out.println(shout("Grace","Java"));
System.out.println(getFilePath("C", "Documents", "rap.mp3"));
System.out.println(epicSqrt(16));
System.out.println(epicSqrt(-16));
System.out.println(noFirstLetterConcat("java","code"));
System.out.println(findVowels("appleapp"));
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started