can anybody help me make this Java Project Name IC17Temperat

can anybody help me make this!

Java Project Name: IC17_Temperature

Implement a class named Temperature that represents a temperature in either Fahrenheit or Celsius. Allow the degrees to have decimal places (e.g. double) and use an enumeratation to store the unit. Name the enumeration TemperatureUnit with the possible values CELSIUS and FAHRENHEIT. Specifically, the Temperature class has the following instance variables (a.k.a. fields or data):

The degrees (double)
The unit (TemperatureUnit - from the enum you created)

The Temperature class will have methods to:

Create a new Temperature (given a value for degrees and unit) [parameterized constructor]
Create a new Temperature (given no parameters - initialize Temperature to 0.0 degrees Celsius) [default constructor]
Create a new Temperature (from another Temperature) [copy constructor]
getDegrees
getUnit
setDegrees
setUnit

convertTo(TemperatureUnit otherUnit) - this method will convert a degree in one unit to a degree in another (e.g. Fahrenheit to Celsius) and returns true if a conversion was made, false otherwise (the only way a conversion is not made is if the units are the same (e.g. Fahrenheit to Fahrenheit)
inOtherUnit(TemperatureUnit otherUnit) - this method will return a new Temperature object in the otherUnit, without changing the current object.
equals - method to check if one Temperature is the same as another by determining if their degrees are the same, after comparing them with the same unit.
toString - method to turn a Temperature into a string for display, e.g. display as \"Temperature [0.0 degrees Celsius]\"

**Create a driver class (TemperatureDemo) to make three temperature objects (in Celsius, Fahrenheit and Kelvin), two of which are the same essential temperatures, but in different units. Check the two equivalent temperatures for equality. Check two different temperatures for inequality. Print all 3 temperatures to the console.***

Solution


//enum for temperature unit
enum TemperatureUnit{
   CELSIUS,FAHRENHEIT
}

//class temperature
class Temperature{
   private double degrees;
   private TemperatureUnit unit;
  
   //default constructor
   public Temperature() {
       this.degrees=0.0;
       this.unit=TemperatureUnit.CELSIUS;
   }
  
   //paramaterized constructor
   public Temperature(double degress,TemperatureUnit unit) {
       this.degrees=degress;
       this.unit=unit;
   }
  
   //copy constructor
   public Temperature(Temperature temp){
       this.degrees=temp.getDegrees();
       this.unit=temp.getUnit();
   }
  
  
   //method to convert one unit into another unit
   public boolean convertTo(TemperatureUnit otherUnit){
       boolean isConverted=true;
       if(otherUnit.equals(this.unit)){
           isConverted=false;
          
           return isConverted;
       }
      
       if(this.unit.equals(TemperatureUnit.CELSIUS)){
           this.degrees=(9*this.degrees)/5 + 32;
           this.unit=TemperatureUnit.FAHRENHEIT; // celsius to fahrenheit conversion
       }else if(this.unit.equals(TemperatureUnit.FAHRENHEIT)){
           this.degrees=((this.degrees - 32)*5)/9; // fahrenheit to celsius conversion
           this.unit=TemperatureUnit.CELSIUS;
       }
      
       return isConverted;
   }
  
  
   //method to convert one unit into another unit and return new temperature object
   public Temperature inOtherUnit(TemperatureUnit otherUnit){
       Temperature temp=new Temperature();
       if(otherUnit.equals(TemperatureUnit.CELSIUS)){
           temp.setDegrees((9*this.degrees)/5 + 32); // celsius to fahrenheit conversion
           temp.setUnit(TemperatureUnit.FAHRENHEIT);   
       }else if(otherUnit.equals(TemperatureUnit.FAHRENHEIT)){
           temp.setDegrees(((this.degrees - 32)*5)/9); // fahrenheit to celsius conversion
           temp.setUnit(TemperatureUnit.CELSIUS);
       }
       return temp;
   }
   // equals method will return true if degree and unit are same
   @Override
   public boolean equals(Object obj) {
       if (obj == this) {
   return true;
   }
       Temperature temp=(Temperature)obj;
       boolean isEqual=false;
       if(temp.getUnit().equals(this.getUnit())){ // if unit are same compare the degree and return
           return temp.getDegrees()==this.getDegrees();
       }else{
           if(this.getUnit().equals(TemperatureUnit.CELSIUS)){ // if unit are not same convert both temperature to same unit and then compare the degree
               this.convertTo(TemperatureUnit.FAHRENHEIT);
           }else{
               this.convertTo(TemperatureUnit.CELSIUS);
           }
          
           return temp.getDegrees()==this.getDegrees();
       }
      
   }
   // method to print the degree and unit of the object
   @Override
   public String toString() {
       return \"Temperature [\"+this.degrees+\" degrees \"+this.unit+\"]\";
   }
  

   public double getDegrees() {
       return degrees;
   }

   public void setDegrees(double degrees) {
       this.degrees = degrees;
   }

   public TemperatureUnit getUnit() {
       return unit;
   }

   public void setUnit(TemperatureUnit unit) {
       this.unit = unit;
   }
}

// driver class for demo
public class TemperatureDemo {

   public static void main(String[] args) {
       Temperature temp=new Temperature();
       System.out.println(temp);
       Temperature temp1=new Temperature(32.0,TemperatureUnit.FAHRENHEIT);
       System.out.println(temp1);
       System.out.println(temp.equals(temp1));
      
      
       Temperature temp2=new Temperature(32.0,TemperatureUnit.CELSIUS);
       System.out.println(temp2);
       Temperature temp3=new Temperature(32.0,TemperatureUnit.FAHRENHEIT);
       System.out.println(temp3);
       System.out.println(temp2.equals(temp3));
      

   }

}

---------------------------------------output----------------------------------------------------------

Temperature [0.0 degrees CELSIUS]
Temperature [32.0 degrees FAHRENHEIT]
true
Temperature [32.0 degrees CELSIUS]
Temperature [32.0 degrees FAHRENHEIT]
false

can anybody help me make this! Java Project Name: IC17_Temperature Implement a class named Temperature that represents a temperature in either Fahrenheit or Cel
can anybody help me make this! Java Project Name: IC17_Temperature Implement a class named Temperature that represents a temperature in either Fahrenheit or Cel
can anybody help me make this! Java Project Name: IC17_Temperature Implement a class named Temperature that represents a temperature in either Fahrenheit or Cel

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site