Based on the java code below, how to develop a Junit code to Test for public class Driver1 using JUNIT code package stubdriver; /** * Converts from one unit to another (e.g., inches to feet) * *...


Based on the java code below, how to develop a Junit code to Test for public class Driver1 using
JUNIT code











package stubdriver;



/**

* Converts from one unit to another (e.g., inches to feet)

*

* @author Prof. David Bernstein, James Madison University

* @version 1.0 (Implemented getMultiplier)

*/

public class UnitConverter1

{





/**

* Default Constructor

*/

public UnitConverter1()

{

}





/**

* Perform a conversion

*

* @param value The number to convert

* @param from The units for value (e.g., "inches")

* @param to The units to convert to (e.g., "feet")

* @return The converted value

*/

publicdouble convert(double value, String from, String to)

{

    double result;



    result = value * getMultiplier(from, to);

    return result;

}







/**

* Get the multiplier needed for a conversion

*

* @param from The units to convert from (e.g., "inches")

* @param to The units to convert to (e.g., "feet")

* @return What "from" needs to be multiplied by to get "to"

*/

publicdouble getMultiplier(String from, String to)

{

    double multiplier;



    multiplier = 1.0;

    if (from.equals("inches")) {



     if (to.equals("feet")) multiplier = 1.0/12.0;

     else if (to.equals("yards")) multiplier = 1.0/12.0/3.0;

     else if (to.equals("miles")) multiplier = 1.0/12.0/3.0/1760.0;



    } else if (from.equals("feet")) {



     if (to.equals("inches")) multiplier = 12.0;

     else if (to.equals("yards")) multiplier = 1.0/3.0;

     else if (to.equals("miles")) multiplier = 1.0/3.0/1760.0;



    } else if (from.equals("yards")) {



     if (to.equals("inches")) multiplier = 3.0*12.0;

     else if (to.equals("feet")) multiplier = 3.0;

     else if (to.equals("miles")) multiplier = 1.0/1760.0;



    } else if (from.equals("miles")) {



     if (to.equals("inches")) multiplier = 12.0*3.0*1760.0;

     else if (to.equals("yards")) multiplier = 1760.0;

     else if (to.equals("feet")) multiplier = 3.0*1760.0;

    }



    return multiplier;

}



}



package stubdriver;


/**
* A driver for testing the UnitConverter class
*
* @author Prof. David Bernstein, James Madison University
* @version 2.0
*/

public class Driver1

{
/**
* The entry point of the application
*
* @param args The command-line arguments
*/
public static void main(String[] args)
{
double converted, original;
int i, j;
String from, to;
String[] units = {"inches","feet","yards","miles"};
UnitConverter1 calculator;




calculator = new UnitConverter1();


original = 10.0;


for (i=0; i < units.length;="" i++)="">
for (j=0; j < units.length;="" j++)="">


from = units[i]; // This could be outside the inner loop
to = units[j];
converted = calculator.convert(original, from, to);
System.out.println(original+" "+from+" = "+converted+" "+to);
}
}
}


}


Jun 06, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here