Answer to Question #326462 in Java | JSP | JSF for 1234

Question #326462


• isWaterFreezing. This function should return the bool value true if the temperature stored in the temperature field is at or below the freezing point of water. Otherwise, the function should return false.

• isWaterBoiling. This function should return the bool value true if the temperature stored in the temperature field is at or above the boiling point of water. Otherwise, the function should return false.

Write a program that demonstrates the class. The program should ask the user to enter a temperature and then display a list of the substances that will freeze at that temperature and those that will boil at that temperature. For example, if the temperature is −20 the class should report that water will freeze and for 100 water will boil.



1
Expert's answer
2022-04-10T05:24:29-0400


import java.util.Scanner;


class TemperatureChecker {


	private double temperature;


	public TemperatureChecker(double t) {
		temperature = t;
	}


	public double getTemperature() {
		return temperature;
	}


	/**
	 * Method should check if the temperature is freezing
	 *
	 * @return true if Water is freezing
	 */
	public boolean isWaterFreezing() {


		if (temperature <= 0.0) {
			return true;
		} else {
			return false;
		}
	}


	/**
	 * Method should check if the temperature is boiling
	 *
	 * @return true if Water is boiling
	 */
	public boolean isWaterBoiling() {


		if (temperature >= 100.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);


		if (temperatureChecker.isWaterFreezing()) {
			System.out.println("Water will freeze.");
		}
		if (temperatureChecker.isWaterBoiling()) {
			System.out.println("Water 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