Question
-----------This is main program------------- public class ConversionFunctions { private static final String[] MONTH_NAMES = { , January, February, March, April, May, June, July, August, September,
-----------This is main program-------------
public class ConversionFunctions {
private static final String[] MONTH_NAMES = { "", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
/** * Convert a temperature from celsius to fahrenheit * @param celsius temperature in degrees celsius * @return the fahrenheit equivalent of the given celsius temp */
public static int celsiusToFahrenheit(int celsius)
{ return (int)(Math.round(9.0*celsius/5) + 32); }
/** * Convert cups to tablespoons. There are 16 tablespoons in a cup.
* @param cups the number of cups to convert
* @return the number of tablespoons in the given number of cups
*/ public static int cupsToTablespoons(int cups)
{ return (int)(Math.round(cups/16)); }
/** * Convert a month number to the string name of the month
* @param monthNum a month number, from 1 to 12
* @return the name of the given month, or empty string if the month number is invalid *
*/ public static String monthNumToMonthName(int monthNum)
{ // This method does not work correctly. You will fix it as you work through the tests. // Remove these comments once it is implemented correctly. return MONTH_NAMES[monthNum]; }
}
________________------------This is test program ---------------_________
import org.junit.Test; import static org.junit.Assert.*;
public class ConversionFunctionsTest {
// celsiusToFahrenheit tests ---------------------------------------------------------------------------
@Test
public void celsius0IsFahrenheit32() {
assertEquals(32, ConversionFunctions.celsiusToFahrenheit(0)); }
@Test public void celsius16IsFahrenheit61() { assertEquals(61, ConversionFunctions.celsiusToFahrenheit(16)); }
// TODO: Write a test for a negative celsius that converts to a positive fahrenheit
@Test public void celsiusNeg10IsFahrenheit14(){ assertEquals(14, ConversionFunctions.celsiusToFahrenheit(-10)); }
// TODO: Write a test for a negative celsius that converts to a negative fahrenheit
@Test public void celsiusNeg20IsFahrenheitNeg4()
{ assertEquals( -4, ConversionFunctions.celsiusToFahrenheit(-20)); }
// TODO: Write a test for a celsius value that converts to 0 fahrenheit
@Test public void celsiusNeg18IsFahrenheit0(){ assertEquals(0, ConversionFunctions.celsiusToFahrenheit(-18)); }
// cupsToTablespoons tests --------------------------------------------------------------------------- //
TODO: Write a test for 0 cups converts to 0 tablespoons - run the test & see that it passes
@Test public void noCupIsNoTablespoons()
{ assertEquals(0, ConversionFunctions.cupsToTablespoons(0)); }
// TODO: Write a test for 1 cup converts to 16 tablespoons @Test
public void oneCupIs16Tablespoons(){ assertEquals(16, ConversionFunctions.cupsToTablespoons(1)); }
// TODO: Run the test & see that it fails. Failing tests reveal bugs.
// TODO: Fix the implementation of cupsToTablespoons so that this test passes
// TODO: Write one or two additional tests for cupsToTablespoons @Test public void threeCupsIs48Tablespoons() { assertEquals(32, ConversionFunctions.cupsToTablespoons(2)); }
@Test public void fifteenCupsIs240Tablespoons() { assertEquals(48, ConversionFunctions.cupsToTablespoons(3)); }
// monthNumToMonthName tests ---------------------------------------------------------------------------
// TODO: Complete the test below so that it tests all valid months @Test public void months1through12AreJanuaryThroughDecember() { assertEquals("january", ConversionFunctions.monthNumToMonthName(1).toLowerCase()); assertEquals("february", ConversionFunctions.monthNumToMonthName(2).toLowerCase()); assertEquals("march", ConversionFunctions.monthNumToMonthName(3).toLowerCase()); assertEquals("april", ConversionFunctions.monthNumToMonthName(4).toLowerCase()); assertEquals("may", ConversionFunctions.monthNumToMonthName(5).toLowerCase()); assertEquals("june", ConversionFunctions.monthNumToMonthName(6).toLowerCase()); assertEquals("july", ConversionFunctions.monthNumToMonthName(7).toLowerCase()); assertEquals("august", ConversionFunctions.monthNumToMonthName(8).toLowerCase()); assertEquals("september", ConversionFunctions.monthNumToMonthName(9).toLowerCase()); assertEquals("october", ConversionFunctions.monthNumToMonthName(10).toLowerCase()); assertEquals("november", ConversionFunctions.monthNumToMonthName(11).toLowerCase()); assertEquals("december", ConversionFunctions.monthNumToMonthName(12).toLowerCase()); }
// TODO: Complete the test below for a variety of invalid month numbers; be sure to include bounds
// TODO: Run the test and see that it fails. Failing tests reveal bugs.
// TODO: Fix the implementation of monthNumToMonthName so that this test passes @Test
public void invalidMonthReturnsEmptyString()
{ assertEquals("", ConversionFunctions.monthNumToMonthName(0).toLowerCase());
assertEquals("", ConversionFunctions.monthNumToMonthName(-2).toLowerCase());
assertEquals("", ConversionFunctions.monthNumToMonthName(14).toLowerCase());
assertEquals("", ConversionFunctions.monthNumToMonthName(1500).toLowerCase()); }
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