class that stores a temperature in a temperature member variable and has the appropriate constructor, setter and getter functions. In addition to these, the class should have the following member functions:
• isEthylFreezing. This function should return the bool value true if the temperature stored in the temperature field is at or below the freezing point of ethyl alcohol. Otherwise, the function should return false.
• isEthylBoiling. This function should return the bool value true if the temperature stored in the temperature field is at or above the boiling point of ethyl alcohol. Otherwise, the function should return false. •
import java.util.Scanner;
class TemperatureChecker {
private double temperature;
/**
* @return the temperature
*/
public double getTemperature() {
return temperature;
}
/**
* @param temperature the temperature to set
*/
public void setTemperature(double temperature) {
this.temperature = temperature;
}
public TemperatureChecker(double t) {
temperature = t;
}
/**
* Method should check if the temperature is freezing
*
* @return true if Ethyl is freezing
*/
public boolean isEthylFreezing() {
if (temperature <= -173.0) {
return true;
} else {
return false;
}
}
/**
* Method should check if the temperature is boiling
*
* @return true if Ethyl is boiling
*/
public boolean isEthylBoiling() {
if (temperature >= 172.0) {
return true;
} else {
return false;
}
}
}
public class App {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter a temperature: ");
double temperature = keyboard.nextDouble();
// close keyboard
keyboard.close();
TemperatureChecker temperatureChecker = new TemperatureChecker(temperature);
// Display elements will freeze.
if (temperatureChecker.isEthylFreezing()) {
System.out.println("Ethyl alcohol will freeze.");
}
// Display if elements will boil.
if (temperatureChecker.isEthylBoiling()) {
System.out.println("Ethyl alcohol will boil.");
}
keyboard.close();
}
}
Comments
Leave a comment