Answer to Question #326461 in Java | JSP | JSF for herry

Question #326461

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. •



1
Expert's answer
2022-04-10T06:27:12-0400


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();
	}


}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS