Question: Download the two source code files of sample code named Temperature.java and TemperatureConverter.java. Those two files make a standalone program which converts Celsius to Fahrenheit

Download the two source code files of sample code named Temperature.java and TemperatureConverter.java.Those two files make a standalone program which converts Celsius to Fahrenheit and Fahrenheit to Celsius.
For this assignment, write a JUnit test case to test two methods in the Temperature class. Test the toCelsius method, and also write a test case to test the toFahrenheit method. You can write both test cases in one class file, which should be a JUnit test file.
Temperature.java
package JunitAssignment;
/*
Chapter 4
This class can be used to convert from Celsius to Fahrenheit and vice versa.
*/
public class Temperature {
//----------------------------------
// Data Members
//----------------------------------
private double fahrenheit =0;
//-------------------------------------------------
// Public Methods:
//
// double toFahrenheit()
// double toCelsius()
//
// void setFahrenheit(double)
// void setCelsius(double)
//------------------------------------------------
public double toFahrenheit(){
return fahrenheit;
}
public double toFahrenheit(double tempC)
{
return (((tempC /5)*9)+32);
}
public double toCelsius()
{
return (5.0/9.0)*( fahrenheit -32);
}
public double toCelsius(double tempF)
{
return (((tempF -32)*5)/9);
}
public void setFahrenheit(double degrees)
{
fahrenheit = degrees;
}
public void setCelsius(double degrees)
{
fahrenheit =1.8* degrees +32;
}
}
TemperatureConverter.java
package JunitAssignment;
/*
Chapter 4
This class can be used to convert from Celsius to Fahrenheit and vice versa.
*/
public class Temperature {
//----------------------------------
// Data Members
//----------------------------------
private double fahrenheit =0;
//-------------------------------------------------
// Public Methods:
//
// double toFahrenheit()
// double toCelsius()
//
// void setFahrenheit(double)
// void setCelsius(double)
//------------------------------------------------
public double toFahrenheit(){
return fahrenheit;
}
public double toFahrenheit(double tempC)
{
return (((tempC /5)*9)+32);
}
public double toCelsius()
{
return (5.0/9.0)*( fahrenheit -32);
}
public double toCelsius(double tempF)
{
return (((tempF -32)*5)/9);
}
public void setFahrenheit(double degrees)
{
fahrenheit = degrees;
}
public void setCelsius(double degrees)
{
fahrenheit =1.8* degrees +32;
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!