import
java.io.*;
import java.text.*;
public class Tempature
{
private double degrees ;
private String scale;
public Tempature()
{
degrees = 0.0f;
scale = "no scale";
}
public void setDegrees(double newDegrees)
{
degrees = newDegrees;
}
public void setScale(String newScale)
{
scale = newScale;
}
public Tempature(double newDegrees, String newScale)
{
degrees = newDegrees;
scale = newScale;
}
public double getTempatureF()
{
if (!scale.equals("C"))
{
degrees = (double)Math.round(degrees * 10d) / 10d;
return degrees;
}
else
{
double degreesF = (9 * (degrees / 5) + 32);
degreesF =(double)Math.round(degreesF * 10d) / 10d;
return degreesF;
}
}
public double getTempatureC()
{
if (!scale.equals("F"))
{
degrees = (double)Math.round(degrees * 10d) / 10d;
return degrees;
}
else
{
double degreesC = (5 * (degrees - 32) / 9);
degreesC =(double)Math.round(degreesC * 10d) / 10d;
return degreesC;
}
}
public boolean getEqual(Tempature temp2)
{
if(this.getTempatureC() == temp2.getTempatureC() && this.getTempatureF() == temp2.getTempatureF())
{
return true;
}
else
return false;
}
}
public class TempatureTester
{
public static void main(String[] args)
{
Tempature tempature1 = new Tempature(0, "C");
System.out.println("Testing the default Constructor using Temp1");
System.out.println("temp1 in C is: " + tempature1.getTempatureC());
System.out.println("temp2 in F is: " + tempature1.getTempatureF());
System.out.println();
Tempature tempature2 = new Tempature(22, "C");
System.out.println("Testing of 3 set methods using Temp2");
System.out.println("new temp2 in C is: " + tempature2.getTempatureC());
System.out.println("new temp2 in F is: " + tempature2.getTempatureF());
tempature2 = new Tempature(22, "F");
System.out.println("new temp2 in C is: " + tempature2.getTempatureC());
System.out.println("new temp2 in F is: " + tempature2.getTempatureF());
tempature2 = new Tempature(100, "C");
System.out.println("new temp2 in C is: " + tempature2.getTempatureC());
System.out.println("new temp2 in F is: " + tempature2.getTempatureF());
System.out.println();
System.out.println("Testing of 3 alternate Constructors using Temp3, Temp4, and Temp5");
Tempature tempature3 = new Tempature(25.22, "C");
System.out.println("temp3 in C is: " + tempature3.getTempatureC());
System.out.println("temp3 in F is: " + tempature3.getTempatureF());
Tempature tempature4 = new Tempature(0, "F");
System.out.println("temp4 in C is: " + tempature4.getTempatureC());
System.out.println("temp4 in F is: " + tempature4.getTempatureF());
Tempature tempature5 = new Tempature(250, "F");
System.out.println("temp5 in C is: " + tempature5.getTempatureC());
System.out.println("temp5 in F is: " + tempature5.getTempatureF());
System.out.println();
System.out.println("Testing to see if 2 are equal using Temp4 and Temp5, should be false");
System.out.println("temp4 equals temp5 is " + tempature4.getEqual(tempature5));
System.out.println();
tempature5 = new Tempature(0, "C");
Tempature tempature6 = new Tempature(32, "F");
System.out.println("Testing to see if 2 are equal using Temp5 as 0 C and new Temp6 as 32 F, should be true");
System.out.println("temp5 equals temp6 is " + tempature5.getEqual(tempature6));
System.out.println();
tempature5 = new Tempature(-40, "C");
tempature6 = new Tempature(-40, "F");
System.out.println("Testing to see if 2 are equal using Temp5 as -40 C and new Temp6 as -40 F, should be true");
System.out.println("temp5 equals temp6 is " + tempature5.getEqual(tempature6));
System.out.println();
tempature5 = new Tempature(100, "C");
tempature6 = new Tempature(212, "F");
System.out.println("Testing to see if 2 are equal using temp5 as 100 C and new temp6 as 212 F, should be true");
System.out.println("temp5 equals temp6 is " + tempature5.getEqual(tempature6));
}
}