Please help, can't figure out why it wont display. I think it has something to do with the setter method for DegreesInCelsius and fahrenheit. on output the answers for temperature 1 fahrenheit and temperature 2 celsius is incorrect.
< public class Temperature { // Instance variable private double degreesInKelvin; // degrees in Kelvin private double degreesInCelsius; private double degreesInFahrenheit; // Constructor method: initialize degrees in Kelvin to zero public Temperature() { degreesInKelvin = 0; degreesInCelsius = 0; degreesInFahrenheit = 0; } // Convert and save degrees in Celsius in the Kelvin scale public void setDegreesFromCelsius(double celsius) { degreesInKelvin = celsius + 273.15; } // Convert and save degrees in Fahrenheit in the Kelvin scale public void setDegreesFromFahrenheit(double fahrenheit) { degreesInKelvin = (5.0 / 9.0) * (fahrenheit - 32) + 273.15; } // Convert and save degrees in Celsius in the Kelvin scale public void setDegreesToCelsius(double fahrenheit) { degreesInCelsius = (fahrenheit - 32) * (5 / 9); } // Convert and save degrees in Fahrenheit in the Kelvin scale public void setDegreesToFahrenheit(double celsius) { degreesInFahrenheit = (celsius - 273.15) * (9/5) + 32; } // Getter method returns the degrees in Kelvin public double getDegreesInKelvin() { return degreesInKelvin; } public double getDegreesInCelsius() { return degreesInCelsius; } public double getDegreesInFahrenheit() { return degreesInFahrenheit; } }>
< import java.util.Scanner; public class TemperatureDemo { public static void main(String args[]) { final double MARGIN_OF_ERROR = 0.0001; // Declare variables double degrees; Temperature temperature1 = new Temperature(); Temperature temperature2 = new Temperature(); // Create a Scanner object to read from the keyboard Scanner keyboard = new Scanner (System.in); // Get the first temperature in Celsius from the user System.out.print("Enter a temperature in Celsius: "); degrees = keyboard.nextDouble(); temperature1.setDegreesFromCelsius(degrees); // Get the second temperature in Fahrenheit from the user System.out.print("Enter a temperature in fahrenheit: "); degrees = keyboard.nextDouble(); temperature2.setDegreesFromFahrenheit(degrees); double difference = temperature1.getDegreesInKelvin() - temperature2.getDegreesInKelvin(); // Display the first temperature in Kelvin System.out.println("\nTemperature 1 in Kelvin is " + temperature1.getDegreesInKelvin()); System.out.println("Temperature 1 in Ceslius is " + temperature1.getDegreesInCelsius()); System.out.println("Temperature 1 in Fahrenheit is " + temperature1.getDegreesInFahrenheit()); // Display the second temperature in Kelvin System.out.println("\nTemperature 2 in Kelvin is " + temperature2.getDegreesInKelvin()); System.out.println("Temperature 2 in Ceslius is " + temperature2.getDegreesInCelsius()); System.out.println("Temperature 2 in Fahrenheit is " + temperature2.getDegreesInFahrenheit()); if (Math.abs(difference) <= MARGIN_OF_ERROR) { System.out.println("\nThe two temperatures are equivalent"); } else { System.out.println("The two temperatures are not equivalent"); } } }>