I NEED THIS IN JAVA. SEPARATE CLASSES FOR TEMPERATURE AND TEMPERATURE DRIVER AND
ID: 3605407 • Letter: I
Question
I NEED THIS IN JAVA. SEPARATE CLASSES FOR TEMPERATURE AND TEMPERATURE DRIVER AND SEPARATE ENUM! i REPEAT A SEPERATE ENUM! Write a class called Temperature that represents temperatures in degrees in both Celsius and Fahrenheit. Use a floating-point number for the temperature field and an enum for the Scale, it should have ‘C’ for Celsius or ‘F’ for Fahrenheit. The class will have four constructors: one for the number of degrees, one for the scale, one for both the degrees and the scale, and a default constructor. For each of these constructors, assume zero degrees if no value is specified and Celsius if no scale is given. The class will have two accessor methods: one to return the temperature in degrees Celsius, the other to return it in degrees Fahrenheit. (Use the formulas from the Practice Program 5 of Chapter 3 and round to the nearest tenth of a degree.) The class will have three mutator methods: one to set the number of degrees, one to set the scale, and one to set both. The class will have three comparison (boolean) methods: one to test whether two temperature objects are equal, one to test whether one temperature is greater than another, and one to test whether one temperature is less than another. Along with the Temperature class and the enum Scale, create a third file which will be a separate driver program calledTemperatureDriver to properly test all of the above methods. Be sure to invoke each of the constructors, to include at least one true and one false case for each of the different comparison methods, and to test at least the following three temperature pairs for equality: 0.0 degrees C and 32.0 degrees F, -40.0 degrees C and -40.0 degrees F, and 100.0 degrees C and 212.0 degrees F. 25 Point Bonus: Expand the project code to properly and correctly add the Kelvin temperature scale not only in the Temperature class and the enum Scale but including the appropriate additional code in the TemperatureDriver class. I FOUND THIS ANSWERED ON CHEGG ALREADY BUT THE ENUM WAS NOT INCLUDED. DO NOT ANSWER IF YOU DO NOT INCLUDE THE ENUM!!!!!!!!!!!!!!!!!!!!!
IT NEEDS TO OUT PUT TRUE OR FALSE WITH EACH TEMPERATURE PAIR!
Explanation / Answer
// Enum Class
package com.sanfoundry.graph;
public enum TempScale {
C, F
};
-----------------------------------------------------------------------------------------
//TEMPERATURE Class
package com.sanfoundry.graph;
public class Temperature {
private double number;
private TempScale scale;
public Temperature(double number) {
super();
this.number = number;
this.scale = TempScale.C;
}
public Temperature(TempScale scale) {
super();
this.scale = scale;
this.number=0;
}
public Temperature(double number, TempScale scale) {
super();
this.number = number;
this.scale = scale;
}
public Temperature() {
super();
this.number=0;
this.scale = TempScale.C;
}
public double getNumberInCELSIUS() {
if(this.scale==TempScale.C)
{
return number;
}
else
{
return (((number - 32)*5)/9);
}
}
public double getNumberInFAHRENHEIT() {
if(this.scale==TempScale.F)
{
return number;
}
else
{
return ((9/5) * number + 32);
}
}
public void setNumber(double number) {
this.number = number;
}
public void setScale(TempScale scale) {
this.scale = scale;
}
public void setTempData(double number,TempScale scale) {
this.number=number;
this.scale = scale;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
long temp;
temp = Double.doubleToLongBits(number);
result = prime * result + (int) (temp ^ (temp >>> 32));
return result;
}
public boolean compareEqualsObjects(Temperature t1,Temperature t2) {
if(t1.getNumberInCELSIUS()==t2.getNumberInCELSIUS())
return true;
else
return false;
}
public boolean compareTempGreaterThan(Temperature t1,Temperature t2) {
if(t1.getNumberInCELSIUS() > t2.getNumberInCELSIUS())
return true;
else
return false;
}
public boolean compareTempLessThan(Temperature t1,Temperature t2) {
if(t1.getNumberInCELSIUS() < t2.getNumberInCELSIUS())
return true;
else
return false;
}
}
------------------------------------------------------------------------------------------------------------------------
//To test temperature class
package com.sanfoundry.graph;
public class TemperatureDriver {
public static void main(String [] args)
{
Temperature t1=new Temperature(32);
Temperature t2=new Temperature(TempScale.F);
Temperature t3=new Temperature(-40,TempScale.C);
Temperature t4=new Temperature();
t2.setNumber(40);
if(t1.compareEqualsObjects(t1, t2))
{
System.out.println("Equal");
}
else
{
System.out.println("Not Equal");
}
if(t2.compareTempGreaterThan(t2, t3))
{
System.out.println("Greater");
}
else
{
System.out.println("Not Greater");
}
if(t2.compareTempGreaterThan(t3, t4))
{
System.out.println("Lesser");
}
else
{
System.out.println("Not Lesser");
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.