Question: COMPLETE THE JUNIT SO ALL TESTS PASS: /** * Name: Firstname Lastname * Chapter 6 methods in the Ebook. Submit this file to * the
COMPLETE THE JUNIT SO ALL TESTS PASS:
/**
* Name: Firstname Lastname
* Chapter 6 methods in the Ebook. Submit this file to
* the dropbox for grading.
* Some methods require you to call a previous defined method.
*
* @version 3.0
*/
public class JU18V
{
// Declare any constants here.
/**
* Write a method that computes the area of a triangle given the base width
* and height.
*
* @return returns a double.
*/
public static double getTriangleArea(int width, int height)
{
// This method requires you to return a double.
return 42.2; // TODO: replace this.
// TODO: Also, did you put your name at the top of this file?
}
/**
* Returns true if a and b are equal or almost equal. They are almost equal if
* the difference between them is less than 0.01. Examples:
*
*
* approxEqual(3.54, 3.542) -> true
* approxEqual(3.542, 3.54) -> true
* approxEqual(3.3, 3.1) -> false
*
*
*/
public static boolean approxEqual(double a, double b)
{
// TODO: Use Math.abs or do it the hard way.
return false;
}
/**
* Returns the sum of two doubles, but if they are approximately
* equal to each other (less than 0.01 difference), then return three
* times the sum of the two parameters.
*
* @param a
* @param b
* @return
*/
public static double funnySum(double a, double b)
{
// Note: YOU MUST CALL A PREVIOUS METHOD TO SOLVE THIS.
// No credit will be awarded if you don't
// call your approxEqual method to solve this.
return 42.2;
}
/**
* This method returns the value of number rounded to nearest one's place. The
* AP way of rounding is actually different than Math.round. It rounds numbers
* "away" from zero. If the number is positive add 0.5 and truncate the value.
* If the number is negative then subtract 0.5 and then truncate the value.
*
*
* roundAP(5.6) -> 6
* roundAP(5.54) -> 6
* roundAP(5.5) -> 6
* roundAP(5.4555) -> 5
* roundAP(-5.6) -> -6
* roundAP(-5.5) -> -6
* roundAP(-5.2) -> -5
*
*
* @param number
* can be negative or positive
* @return see above
*/
public static int roundAP(double number)
{
// The return type of this method is "int"
// that means you have to return an integer, not
// something in between quotes (aka String)
return 42;
}
/**
* Very similar to roundAP, except that it rounds to the nearest hundredths
* place. Multiply by 100, then add 0.5, then chop off the decimal, then
* divide by 100.0
*
*
* roundAP(5.389) -> 5.39
* roundAP(2.612) -> 6.12
* roundAP(-8.225) -> -8.23
* roundAP(-8.224) -> -8.22
*
*
* @param number
* can be negative or positive
* @return see above
*/
public static double roundAPHundredths(double number)
{
// The return type of this method is "int"
// that means you have to return an integer, not
// something in between quotes (aka String)
return 42.0;
}
/**
* Visit
* https://www.thecalculatorsite.com/articles/finance/compound-interest-formula.php
* and find the compound interest formula.
*
*
* principle = the principal investment amount (the initial deposit or loan amount)
* rate = the annual interest rate (in percentage)
* numberOftimes = the number of times that interest is compounded per unit t
* times = the time the money is invested or borrowed for
*
*
* @return the future value of the investment/loan, including interest
*/
public static String compoundInterest(double principle, double rate,
int numberOfTimes, double time)
{
// Note: YOU MUST CALL A PREVIOUS METHOD TO SOLVE THIS.
// You must call the roundAPHundredths to solve this.
double a = 42.0; // delete if you need to.
String sentence = "";
// You can either use this code or delete it.
sentence +=
" times per year for " + time + " years is $" + roundAPHundredths(a);
return sentence;
}
/**
* Given three values, x, y, and z, is it possible to add any two of the
* parameters where the sum would equal the third one. Examples:
*
*
* sumOfTwoMakesThird(2, 5, 7) -> true because 2 + 5 == 7
* sumOfTwoMakesThird(4, 9, 5) -> true because 4 + 5 == 9
* sumOfTwoMakesThird(5, 4, 7) -> false because no two numbers sum to the third.
* sumOfTwoMakesThird(0, 2, 2) -> false because no two numbers sum to the third.
*
*/
public static boolean sumOfTwoMakesThird(int x, int y, int z)
{
// Use if statements with the OR operator.
return false;
}
/**
*
* Returns true if number is a multiple of 5 or 7.
*
*
* isMultipleOf5or7(14) -> true
* isMultipleOf5or7(19) -> false
* isMultipleOf5or7(42) -> true
*
*
* @param number
* is any real number
* @return true if multiple of 5 or 7, false if not.
*/
public static boolean isMultipleOf5or7(int number)
{
// Your first boolean returning method.
// Make sure you return a true or false at some point in this code.
// You will use an if statement to solve this.
// TODO: finish
return false;
}
/**
* Return a string of numbers that are divisible
* by five or seven up to max.
*
*
* numbersMult5or7(10) -> "5,7,10,"
* numbersMult5or7(17) -> "5,7,10,14,15,"
*
*
* @param max
* @return
*/
public static String numbersMult5or7(int max)
{
// Note: YOU MUST CALL A PREVIOUS METHOD TO SOLVE THIS.
// DO NOT USE MOD IN THIS PROBLEM,
// Call your nifty isMultipleOf5or7 method in your
// if statement.
return "Forty Two";
}
/**
* The formula for this is in your eBook on page 217.
* Actually, the whole line of code is there.
*
*
* convertToFahrenheit(100) -> 212.0
* convertToFahrenheit(0) -> 32.0
*
*
* @param celcius
* @return
*/
public static double convertToFahrenheit(double degreesCelsius)
{
// The formula for this is in your book on page 217.
double answer = (9.0 / 5) * degreesCelsius + 32;
return answer;
}
/**
* The formula for this is in your eBook on page 217.
* Actually, the whole line of code is there.
*
*
* convertToCelsius(212) -> 100.0
* convertToCelsius(32) -> 0
*
*
* @param celcius
* @return
*/
public static double convertToCelsius(double degreesFahrenheit)
{
// The formula for this is in your book on page 217.
double answer = (5.0 / 9) * (degreesFahrenheit - 32);
return answer;
}
/**
* Given a range of temperatures and the step value for
* those temps, you will create a table that shows
* the fahrenheit to celsius conversion. You must
* not repeat code that was used to solve fahrenheitToCelsius.
* See the tests for the formatting.
*
*
* getCelsiusTemps(32, 35, 1) will return:
Fahrenheit Celsius
------------------
32 0.0
33 0.56
34 1.11
35 1.67
------------------
*
*
* @param cMin
* is the first temperature to convert.
* @return a table of fahrenheit to celsius conversions.
*/
public static String getCelsiusTemps(int cMin, int cMax, int step)
{
String sentence = "Fahrenheit Celsius ";
// Do not use multiplication or division in this problem.
// Call your previous convertToCelsius method to help solve this.
return sentence;
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
