Goodday everybody,
So I made a class Temperature, which has a constructor to make the temperature.
Temperature is an arraylist of 2 numbers [coldness, hotness].
public int hotness;
public int coldness;
public int[] temperature;
public int maxTemperature = 10000;
//Constructor Temperature
public Temperature(int hotness, int coldness) {
/**
* A constructor for the Array Temperature
*/
maxTemperature = getMaxTemperature();
if(hotness <= maxTemperature && coldness <= maxTemperature)
temperature[0] = coldness;
temperature[1] = hotness;
}
and now I want to go into another class and use that object Temperature to do some calculations. Here is the code for it.
//Variabels
public int volatility;
private static Temperature temperature;
private static int intrensicExplosivity;
public static int standardVolatility(){
if(temperature[0] == 0){
int standardVolatility = 100 * intrensicExplosivity * (0.10 * temperature[1]);
}
so now I get the error: The type of the expression must be an array type but it resolved to “Temperature”
any solutions?
I’m quite new to Java, so it’s probably just some synthax errors, but I just can’t find it.
thanks in advance.
David
Instead of
try
Note that the
temperaturein your second snippet is of typeTemperaturewhich itself has an int-array calledtemperature. To access thetemperature-array of theTemperatureobject, you’ll have to dotemperature.temperature.As @Marko Topolnik points out, you may also want to change
to
in order to make room for the two temperature values.