Write a temperature class.In addition to converting between Celsius and Fahrenheit also include Kelvin. The class has read(), add(Temperature), subtract(Temperature), Multiply(Temperature), divide(double), equals(Temperature), toKelvin(), toFarhrenheit(), toCelsius(), and toString() methods. Methods add , subtract, multiply and divide all return a Temperature.

public class Temperature {
	   
    public double temperature;
    public char scale; 
    
    public Temperature(double temperature, char scale)
    {
        this.temperature=temperature;
        this.scale=scale;
    }
   
    public Temperature() 
    {
	}

	public Temperature toKelvin()
    {
        double converted_Temp;
        
       
        
        
        if(scale == 'C')
        {
            converted_Temp=(temperature+273.15);
            Temperature temp = new Temperature(converted_Temp, 'K');
            return temp;
        }
       
        if(scale == 'F')
        {
            converted_Temp=(double)((temperature-32)*5.0/9.0+273.15);
            Temperature temp = new Temperature(converted_Temp, 'K');
            return temp;
        }
        if(temperature < 0) 
        { 
              System.out.println("K cannot be < 0"); 
              System.exit(0); 
        } 
       
        return this;
    }
   
    public Temperature toCelsius()
    	{
        double converted_Temp;
 
        if(scale == 'K')
        {
            converted_Temp=temperature-273.15;
            Temperature temp = new Temperature(converted_Temp, 'C');
            return temp;
        }
    
        if(scale == 'F')
        {
            converted_Temp=(double)((temperature-32)*5.0/9.0);
            Temperature temp = new Temperature(converted_Temp, 'C');
            return temp;
        }
        if(temperature < -273.15) 
        { 
              System.out.println("C cannot be < -273.15"); 
              System.exit(0); 
        } 
       
        return this;
    }
   
    public Temperature toFahrenheit()
    {
        double converted_Temp;
 
        if(scale == 'K')
        {
            converted_Temp=(double)(temperature -273.15)*9.0/5.0+32;
            Temperature temp = new Temperature(converted_Temp, 'F');
            return temp;
        }

        if(scale == 'C')
        {
            converted_Temp=(double)(temperature*9.0/5.0 +32);
            Temperature temp = new Temperature(converted_Temp, 'F');
            return temp;
        }
        if(temperature < -459.67) 
        { 
              System.out.println("F cannot be < -459.67"); 
              System.exit(0); 
        } 
        return this;
    }
   

    public Temperature add(Temperature n)
    {
        Temperature temp1 = this.toKelvin();
        Temperature temp2 = n.toKelvin();
       
        return new Temperature(temp1.temperature+temp2.temperature, 'K');
    }
   
    public Temperature subtract(Temperature n)
    {
        Temperature temp1 = this.toKelvin();
        Temperature temp2 = n.toKelvin();
       
        return new Temperature(temp1.temperature-temp2.temperature, 'K');
    }
   
    public Temperature multiply(Temperature n)
    {
        Temperature temp1 = this.toKelvin();
        Temperature temp2 = n.toKelvin();
       
        return new Temperature(temp1.temperature*temp2.temperature, 'K');
    }
   
    public Temperature divide(double d)
    {
        Temperature temp1 = this.toKelvin();
        double new_temp=(double)(temp1.temperature/d);
       
        return new Temperature(new_temp, 'K');
    }
   

    public boolean equals(Temperature n)
    {
        return this.temperature==n.temperature&&this.scale==n.scale;
    }

    public String toString() 
    {
        return "Temperature{" + "temperature=" + temperature + "scale=" + scale + '}';
    }
   

    public void read()
    {
        System.out.println(this);
    }
}
public class TemperatureDemo 
{ 
        public static final int ARRAY_SIZE = 5; 
        public static void main(String[] args) 
         { 
                 int x; 
                 Temperature temp1 = new Temperature(120.0, 'C'); 
                 Temperature temp2 = new Temperature(100, 'F'); 
                 Temperature temp3 = new Temperature(50.0, 'C'); 
                 Temperature temp4 = new Temperature(232.0, 'K'); 
                 Temperature tempAve = new Temperature(0.0, 'C'); 
                 // create array 
                 // fill array with empty temperatures 
                 // this will be discussed in class 
                 System.out.println("Temp1 is " + temp1); 
                 temp1 = temp2.toKelvin(); 
                 System.out.println("Temp1 to Kelvin is " + temp1); 
                 if (temp1.equal(temp3)) 
                 { 
                         System.out.println("These two temperatures are equal"); 
                 } 
                 else 
                 { 
                         System.out.println("These two temperature are not equal"); 
                 } 
                 System.out.println("Temp1 is " + temp1); 
                 System.out.println("Temp2 is " + temp2); 
                 System.out.println("Temp3 is " + temp3); 
                 System.out.println("Temp4 is " + temp4); 

                 tempAve = tempAve.add(temp1); 
                 tempAve = tempAve.add(temp2); 
                 tempAve = tempAve.add(temp3); 
                 tempAve = tempAve.add(temp4); 
                 tempAve = tempAve.divide(4); 
                 System.out.println("the average temperature is " + tempAve ); 

                 readTemperatures(tempArray);// must write this method 
                 tempAve = getAverage(tempArray); // must write this method 
                 System.out.println("the average of the array of temperatures is       " + tempAve ); 
         } 
                 public static void readTemperatures(Temperature[] array) 
                 {  Static method written by you. 
                 } 
                 public static Temperature getAverage(Temperature[] array) 
                 {  Static method written byyou 
                 } 
}

I'm having problems with this part:

readTemperatures(tempArray);// must write this method 
                 tempAve = getAverage(tempArray); // must write this method 
                 System.out.println("the average of the array of temperatures is       " + tempAve ); 
         } 
                 public static void readTemperatures(Temperature[] array) 
                 {  Static method written by you. 
                 } 
                 public static Temperature getAverage(Temperature[] array) 
                 {  Static method written by you 
                 }

I pretty much have the whole assignment complete, but I am having trouble with this last part. This is what I have so far and I'm not sure where to go from here. Any help would be greatly appreciated!

Temperature tempArray [] = new Temperature [ARRAY_SIZE];
        {
        	for (int i = 0; i < tempArray.length; i++)
        	{
        		tempArray[i]= new Temperature();
        	}

I am having trouble with this last part

Please explain what your problem is. If you are getting errors, copy and paste the full text of the error message here.
What is that last piece of code you posted supposed to be doing?

I'm not getting any errors, but I haven't completed the full assignment. The last piece of code I posted was the array I created. The only thing I have left to do is to make 2 static methods that are readTemperatures(Temperature[] array) and getAverage(Temperature[] array). The methods are supposed to use the array I created. I'm very confused about how to use arrays and how to set up these methods. Thanks for your help!

I'm very confused about how to use arrays

Do one thing at a time. Write a few simple programs that work with arrays. Put numbers into an array and print out its contents.

Before you write the code for those methods, you need to define what arguments the method should get when it is called (if any), what the method is supposed to do with those arguments and what the method should return to its caller (if anything).

Ok, I'm reading some things on using arrays now. I also have a question about my add(), subtract(), multiply(), and divide() methods. I convert the temperature to Kelvin for each one, but today I was told I shouldn't do that. I'm supposed to be able to use any degree and return any degree for all four of those methods. I was wondering if you could help me to fix this?

Sorry, I have no idea what it means to multiply or divide one temperature by another.

Can you show an example of what you mean by those arithmetic operations with temperatures?

You can see how the program works in the temperature demo. I have the methods in my temperature class, but they only return Kelvin temperatures. They should be able to return all temperatures.

They should be able to return all temperatures.

What controls which type of temperature a method returns?

I still have a question about making the static method Temperature getAverage. I am referring to the static method at the end of my TemperatureDemo. This is what I have right now.

public static void readTemperatures(Temperature[] array)
{ 
	for (int i = 0; i < array.length; i++)
	{
		array[i].read();
		System.out.println("array[i] " + array[i]); 
	}
}
public static Temperature getAverage(Temperature[] array) 
{ 
	Temperature tempAve;
	
    
    	for (int i = 0; i < array.length; i++)
    	{
    		tempArray[i]= new Temperature();
    	}

The algorithm for the method is:
1.) put first array element in tempAve
2.)in a for loop add other 4 temperatures
3.) find average

Could someone please help me? Thanks a lot.

Where have you written the code for the 3 steps you just listed?
You define a variable: tempAve but never give it a value.
Where is the array: tempArray defined?

The readTemperatures method calls the read() method of the Temperature objects in the array passed to it and then prints them out using the Temperature class's toString method. Is that method doing what you want it to do?
It currently is broken because it does not return a Temperature object.

The getTemperature method is supposed to return a Temperature object. What is supposed to be in the object it returns? You need to define what this method is supposed to do.
It currently fills array with new Temperature objects.

I need help with making my read() method in the Temperature class.

Here are my two static methods at the end of the TemperatureDemo class.

public static void readTemperatures(Temperature[] array)
{ 
	for (int i = 0; i < array.length; i++)
	{
		array[i] = new Temperature();
		array[i].read();
		System.out.println("array[i] " + array[i]); 
	}
}
public static Temperature getAverage(Temperature[] array) 
{ 
	Temperature sum = array[0];
	for(int i = 1; i < array.length; i++) 
        {
		sum = sum.add(array[i]);
        }
	Temperature tempAve = new Temperature(sum.temperature/array.length, 'K');
	return tempAve;
	
}
}

I call my read() method here, but I'm not sure how to set up my read() method. Thanks for the help

What is the read() method supposed to do?

array[i].read();

This code does not save anything returned by the read method.

the read() method is supposed to read in the 5 different temperatures.

You need to give a lot more details about what the read method is supposed to do.
Does it read from a file or where does it get the 5 different temperatures?
What does it do with the temperatures after it reads them in?
Does it read 5 temperatures for each element in the array[]?

sorry, I'm just a little confused about the read() method myself. I believe the read method reads the 5 different temperatures that are in the TemperatureDemo from the array.

You need to understand what you want the read() method to do BEFORE you try to write it.

public String toString() 
    {
        return "" + temperature + " " + scale  ;
    }
   
    public String read()
    {
    return this.toString();
    System.out.println(this);
    }

Does this look right at all? I'm not sure what to put in the parentheses at the end of system.out.println. I'm also not sure if I need to involve the array at all.

Why is the method called read if it only calls the toString()?
I don't think you need a method that only calls the toString method.

Does this look right at all?

What did the compiler say when you tried to compile it?


You need to understand what you want the read() method to do BEFORE you try to write it.

I want the read() to read in the different temperatures from the array. I'm completely at a loss for how to set this up though.

The idea of my read() method should be to read in and initialize the values for the instance fields of my Temperature object. So what in the Temperature class needs to be initialized with a value? I know this shouldn't be so hard, but I'm really at a loss.

public class Temperature {
	   
    public double temperature;
    public char scale; 
    
    public Temperature(double temperature, char scale)
    {
        this.temperature=temperature;
        this.scale=scale;
    }
   
    public Temperature() 
    {
	}

	public Temperature toKelvin()
    {
        double converted_Temp;
         
        
        if(scale == 'C')
        {
            converted_Temp=(temperature+273.15);
            Temperature temp = new Temperature(converted_Temp, 'K');
            return temp;
        }
       
        if(scale == 'F')
        {
            converted_Temp=(double)((temperature-32)*5.0/9.0+273.15);
            Temperature temp = new Temperature(converted_Temp, 'K');
            return temp;
        }
        if(temperature < 0) 
        { 
              System.out.println("K cannot be < 0"); 
              System.exit(0); 
        } 
       
        return this;
    }
   
    public Temperature toCelsius()
    	{
        double converted_Temp;
 
        if(scale == 'K')
        {
            converted_Temp=temperature-273.15;
            Temperature temp = new Temperature(converted_Temp, 'C');
            return temp;
        }
    
        if(scale == 'F')
        {
            converted_Temp=(double)((temperature-32)*5.0/9.0);
            Temperature temp = new Temperature(converted_Temp, 'C');
            return temp;
        }
        if(temperature < -273.15) 
        { 
              System.out.println("C cannot be < -273.15"); 
              System.exit(0); 
        } 
       
        return this;
    }
   
    public Temperature toFahrenheit()
    {
        double converted_Temp;
 
        if(scale == 'K')
        {
            converted_Temp=(double)(temperature -273.15)*9.0/5.0+32;
            Temperature temp = new Temperature(converted_Temp, 'F');
            return temp;
        }

        if(scale == 'C')
        {
            converted_Temp=(double)(temperature*9.0/5.0 +32);
            Temperature temp = new Temperature(converted_Temp, 'F');
            return temp;
        }
        if(temperature < -459.67) 
        { 
              System.out.println("F cannot be < -459.67"); 
              System.exit(0); 
        } 
        return this;
    }
   

    public Temperature add(Temperature n)
    {
        Temperature temp1 = this.toKelvin();
        Temperature temp2 = n.toKelvin();
       
        return new Temperature(temp1.temperature+temp2.temperature, 'K');
    }
   
    public Temperature subtract(Temperature n)
    {
        Temperature temp1 = this.toKelvin();
        Temperature temp2 = n.toKelvin();
       
        return new Temperature(temp1.temperature-temp2.temperature, 'K');
    }
   
    public Temperature multiply(Temperature n)
    {
        Temperature temp1 = this.toKelvin();
        Temperature temp2 = n.toKelvin();
       
        return new Temperature(temp1.temperature*temp2.temperature, 'K');
    }
   
    public Temperature divide(double d)
    {
        Temperature temp1 = this.toKelvin();
        double new_temp=(double)(temp1.temperature/d);
       
        return new Temperature(new_temp, 'K');
    }
   

    public boolean equals(Temperature n)
    {
        return this.temperature==n.temperature&&this.scale==n.scale;
    }

    public String toString() 
    {
        return "" + temperature + " " + scale  ;
    }
   
    	public void read()
    	   {
    	   double temperature = 0;
    	   Temperature[] array = new Temperature[5];
    	   for (int i = 0; i < array.length; i++)
    	   {
    	   	array[i] = new Temperature();
    	   }

    }
public class TemperatureDemo 
{ 
        public static final int ARRAY_SIZE = 5; 
        public static void main(String[] args) 
         { 
                 int x; 
                 Temperature temp1 = new Temperature(120.0, 'C'); 
                 Temperature temp2 = new Temperature(100, 'F'); 
                 Temperature temp3 = new Temperature(50.0, 'C'); 
                 Temperature temp4 = new Temperature(232.0, 'K'); 
                 Temperature tempAve = new Temperature(0.0, 'C'); 
                 // create array 
                 // fill array with empty temperatures 
                 // this will be discussed in class 
                 System.out.println("Temp1 is " + temp1); 
                 temp1 = temp2.toKelvin(); 
                 System.out.println("Temp1 to Kelvin is " + temp1); 
                 if (temp1.equals(temp3)) 
                 { 
                         System.out.println("These two temperatures are equal"); 
                 } 
                 else 
                 { 
                         System.out.println("These two temperature are not equal"); 
                 } 
                 System.out.println("Temp1 is " + temp1); 
                 System.out.println("Temp2 is " + temp2); 
                 System.out.println("Temp3 is " + temp3); 
                 System.out.println("Temp4 is " + temp4); 

                 tempAve = tempAve.add(temp1); 
                 tempAve = tempAve.add(temp2); 
                 tempAve = tempAve.add(temp3); 
                 tempAve = tempAve.add(temp4); 
                 tempAve = tempAve.divide(4); 
                 System.out.println("the average temperature is " + tempAve );
                 Temperature tempArray [] = new Temperature [ARRAY_SIZE];
                 readTemperatures(tempArray);// must write this method 
                 tempAve = getAverage(tempArray); // must write this method 
                 System.out.println("the average of the array of temperatures is       " + tempAve ); 
                 
         }  


public static void readTemperatures(Temperature[] array)
{ 
	for (int i = 0; i < array.length; i++)
	{
		array[i] = new Temperature();
		array[i].read();
		System.out.println("array[i] " + array[i]); 
	}
}
public static Temperature getAverage(Temperature[] array) 
{ 
	Temperature sum = array[0];
	for(int i = 1; i < array.length; i++) 
        {
		sum = sum.add(array[i]);
        }
	Temperature tempAve = new Temperature(sum.temperature/array.length, 'K');
	return tempAve;
	
}
}

My output is :
Temp1 is 120.0 C
Temp1 to Kelvin is 310.92777777777775 K
These two temperature are not equal
Temp1 is 310.92777777777775 K
Temp2 is 100.0 F
Temp3 is 50.0 C
Temp4 is 232.0 K
the average temperature is 362.5388888888889 K
array 0.0
array 0.0
array 0.0
array 0.0
array 0.0
the average of the array of temperatures is 0.0 K

So as you can see, I'm still getting no numbers at the end for the Temperatures. What am I doing wrong?

read() method should be to read in and initialize the values for the instance fields of my Temperature object.

Where does the read() method "read in" the values from?
Does it ask the user for the values
or does read the values from a file?
Or from where?

In the read() method you posted, you create two local variables: temperature and array and give them values.
When the read() method exits, both of those variables go out of scope and are thrown away by the JVM. Nothing remains of what was done in the read() method when the read method returns to its caller.

I suggest that you don't try to do the conversion as a Temperature object; just use (some type of) a floating-point container to hold the values as you iterate through your Temperature array. Do the math, then return a new Temperature object.

AFTER you've fixed that, I recommend changing your class so that it only stores in one scale. In your constructor, you would convert it to the default scale and store it that way. So when you do another conversion at user request, only one type of conversion needs to take place.

I just read your equals method.
What result would you expect from this?

Temperature t1 = new Temperature(32, 'F');
Temperature t2 = new Temperature(0, 'C');
System.out.println(t1.equals(t2));

I need help with my add(Temperature), subtract(Temperature), multiply(Temperature), and divide(Temperature) methods. Right now I convert everything to Kelvin for these methods, but I want to be able to return a Temperature in any degree. The program should return a temperature in the degree that it started as. For instance if I have 50 C + 20 F then the return temperature should be in celsius. If I have 50 K + 30 C then the return temperature should be in kelvin. I have pasted my Temperature class and TemperatureDemo class below.

import java.util.Scanner;
public class Temperature {
	   
    public double temperature;
    public char scale; 
    
    public Temperature(double temperature, char scale)
    {
        this.temperature=temperature;
        this.scale=scale;
    }
    public Temperature(Temperature t)
    {
        this.temperature=t.temperature;
        this.scale=t.scale;
    }
   
    public Temperature() 
    {
	}

	public Temperature toKelvin()
    {
        double converted_Temp;
         
        
        if(scale == 'C')
        {
            converted_Temp=(temperature+273.15);
            Temperature temp = new Temperature(converted_Temp, 'K');
            return temp;
        }
       
        if(scale == 'F')
        {
            converted_Temp=(double)((temperature-32)*5.0/9.0+273.15);
            Temperature temp = new Temperature(converted_Temp, 'K');
            return temp;
        }
        if(temperature < 0) 
        { 
              System.out.println("K cannot be < 0"); 
              System.exit(0); 
        } 
       
        return this;
    }
   
    public Temperature toCelsius()
    	{
        double converted_Temp;
 
        if(scale == 'K')
        {
            converted_Temp=temperature-273.15;
            Temperature temp = new Temperature(converted_Temp, 'C');
            return temp;
        }
    
        if(scale == 'F')
        {
            converted_Temp=(double)((temperature-32)*5.0/9.0);
            Temperature temp = new Temperature(converted_Temp, 'C');
            return temp;
        }
        if(temperature < -273.15) 
        { 
              System.out.println("C cannot be < -273.15"); 
              System.exit(0); 
        } 
       
        return this;
    }
   
    public Temperature toFahrenheit()
    {
        double converted_Temp;
 
        if(scale == 'K')
        {
            converted_Temp=(double)(temperature -273.15)*9.0/5.0+32;
            Temperature temp = new Temperature(converted_Temp, 'F');
            return temp;
        }

        if(scale == 'C')
        {
            converted_Temp=(double)(temperature*9.0/5.0 +32);
            Temperature temp = new Temperature(converted_Temp, 'F');
            return temp;
        }
        if(temperature < -459.67) 
        { 
              System.out.println("F cannot be < -459.67"); 
              System.exit(0); 
        } 
        return this;
    }
   

    public Temperature add(Temperature n)
    {
        Temperature temp1 = this.toKelvin();
        Temperature temp2 = n.toKelvin();
       
        return new Temperature(temp1.temperature+temp2.temperature, 'K');
    }
   
    public Temperature subtract(Temperature n)
    {
        Temperature temp1 = this.toKelvin();
        Temperature temp2 = n.toKelvin();
       
        return new Temperature(temp1.temperature-temp2.temperature, 'K');
    }
   
    public Temperature multiply(Temperature n)
    {
        Temperature temp1 = this.toKelvin();
        Temperature temp2 = n.toKelvin();
       
        return new Temperature(temp1.temperature*temp2.temperature, 'K');
    }
   
    public Temperature divide(double d)
    {
        Temperature temp1 = this.toKelvin();
        double new_temp=(double)(temp1.temperature/d);
       
        return new Temperature(new_temp, 'K');
    }
   

    public boolean equals(Temperature n)
    {
        return this.temperature==n.temperature&&this.scale==n.scale;
    }

    public String toString() 
    {
        return "" + temperature + " " + scale  ;
    }
   
    public void read()
    {
        Scanner input = new Scanner(System.in);
        System.out.print("Enter the scale(C, K, F): ");
        scale = input.nextLine().charAt(0);
        System.out.print("Enter the temperature: ");
        temperature = Double.parseDouble(input.nextLine());

    }

}
public class TemperatureDemo 
{ 
        public static final int ARRAY_SIZE = 5; 
        public static void main(String[] args) 
         { 
                 int x; 
                 Temperature temp1 = new Temperature(120.0, 'C'); 
                 Temperature temp2 = new Temperature(100, 'F'); 
                 Temperature temp3 = new Temperature(50.0, 'C'); 
                 Temperature temp4 = new Temperature(232.0, 'K'); 
                 Temperature tempAve = new Temperature(0.0, 'C'); 
                 // create array 
                 // fill array with empty temperatures 
                 // this will be discussed in class 
                 System.out.println("Temp1 is " + temp1); 
                 temp1 = temp2.toKelvin(); 
                 System.out.println("Temp1 to Kelvin is " + temp1); 
                 if (temp1.equals(temp3)) 
                 { 
                         System.out.println("These two temperatures are equal"); 
                 } 
                 else 
                 { 
                         System.out.println("These two temperature are not equal"); 
                 } 
                 System.out.println("Temp1 is " + temp1); 
                 System.out.println("Temp2 is " + temp2); 
                 System.out.println("Temp3 is " + temp3); 
                 System.out.println("Temp4 is " + temp4); 

                 tempAve = tempAve.add(temp1); 
                 tempAve = tempAve.add(temp2); 
                 tempAve = tempAve.add(temp3); 
                 tempAve = tempAve.add(temp4); 
                 tempAve = tempAve.divide(4); 
                 System.out.println("the average temperature is " + tempAve );
                 Temperature tempArray [] = new Temperature [ARRAY_SIZE];
                 readTemperatures(tempArray);// must write this method 
                 tempAve = getAverage(tempArray); // must write this method 
                 System.out.println("the average of the array of temperatures is       " + tempAve ); 
                 
         }  


public static void readTemperatures(Temperature[] array)
{ 
	for (int i = 0; i < array.length; i++)
	{
		array[i] = new Temperature();
		array[i].read();
		System.out.println("array[i] " + array[i]); 
	}
}
public static Temperature getAverage(Temperature[] array) 
{ 
	Temperature answer = new Temperature(array[0]);
	
	//double doubleAverage = 0;
	for(int i = 1; i < array.length; i++) 
        {
		answer = answer.add(array[i]);
		System.out.println("answer " + answer); 
        }
	
	return new Temperature(answer.divide(array.length));
	
}
}

I want to be able to return a Temperature in any degree.

Can you describe how the add() method determines what scale of temperature it is working with? I see in the Temperature constructor that you pass a char that says what scale of temperature the data being passed is. How would the add method know what scale the value that it is to add to the current value of the Temperature object?

If you create a Temperature object with scale F can you add to it degrees in C?
What scale would the returned value be in?

The returned value is always the same scale as the first value. If you have 50 C and then add 25 F, the return value would be in Celsius. The add method determines the scale because the user will inputs it.

Are you writing completely new add methods that will ask the user for the scale of the value?
What is the add() method you have in the code now used for?
It is used in several places.

What class will the new add() method go in?
Where will the new add method() be called?

Sorry, my last post wasn't clear. I am not making a new add method, I just need to fix mine. You can see where the add method is invoked in the TemperatureDemo class. For instance when I run the program at the end I am supposed to enter 5 temperatures and it will find their average. So if my temps are 50 C, 25 F, 100 C, 10 F, and 20 C. My program should find the average in degrees Celsius since the first temp was in degrees Celsius. Right now my program just converts it to Kelvin then finds the average. I think the method should go something like temp1 + temp2. Convert temp2 to same scale as temp1 then add them. Does that make sense?

You said:

The add method determines the scale because the user will inputs it.

If the Temperature class was created with scale K, how do you add a C temperature to it?
Where does the add() method get the scale for the addition it is to do?
Do you pass the scale to the add method, like you do in the constructor?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.