The following table lists the freezing and boiling points of several substances.
ID: 669151 • Letter: T
Question
The following table lists the freezing and boiling points of several substances.
Design a class that stores a temperature in a temperature field and has the appropriate accessor andmutator methods for the field. In addition to appropriate constructors, the class should have the following methods:
isEthylFreezing. This method should return the boolean value true if the temperature stored in the temperature field is at or below the freezing point of ethyl alcohol. Otherwise, the method should return false.
isEthylBoiling. This methodshould return the boolean value true if the temperature stored in the temperature field is at or above the boiling point of ethyl alcohol. Otherwise, the method should return false.
isOxygenFreezing. This method should return the boolean value true if the temperature stored in the temperature field is at or below the freezing point of oxygen. Otherwise, the method should return false.
isOxygenBoiling. This method should return the boolean value true if the temperature stored in temperature field is at or above the boiling point of oxygen. Otherwise,the method should return false.
isWaterFreezing. This method should return the boolean value true if the temperature stored in the temperature field is at or below the freezing point of water. Otherwise, the method should return false.
isWaterBoiling. This method should return the boolean value true if the temperature stored in the temperature field is at or above the boiling point of water. Otherwise, the method should return false.
Write a program that demonstrate the class. The program should ask the user to enter a temperature, and then display a list of the substance 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 oxygen will boil at that temperature.
--- Create a Substance class- create a FreezeBoil object and display the substances that will freeze and boil.
--- Run the program 3 times with the following tempertures: 65,-264, -43. Output wheater the substances freeze/boil at these temperatures.
Substance Freezing Point Boiling Point Ethyl Alcohol -173 172 Oxygen -362 -306 Water 32 212Explanation / Answer
FREEZE AND BOILING CLASS:
public class FreezeAndBoiling
{
private double temperature;
public FreezeAndBoiling(double t)
{
temperature = t;
}
public double getTemperature()
{
return temperature;
}
public boolean isEthylAlchoolFreezing()
{
if (temperature <= -173.0)
{
return true;
}
else
{
return false;
}
}
public boolean isEthylAlchoolBoiling()
{
if (temperature >= 172.0)
{
return true;
}
else
{
return false;
}
}
public boolean isOxygenFreezing()
{
if (temperature <= -362.0)
{
return true;
}
else
{
return false;
}
}
public boolean isOxygenBoiling()
{
if (temperature >= -306.0)
{
return true;
}
else
{
return false;
}
}
public boolean isWaterFreezing()
{
if (temperature <= 32.0)
{
return true;
}
else
{
return false;
}
}
public boolean isWaterBoiling()
{
if (temperature >= 212.0)
{
return true;
}
else
{
return false;
}
}
}
PROGRAM:
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter a temperature: ");
double temperature = keyboard.nextDouble();
keyboard.close();
FreezingAndBoilingPoints freezeAndBoilingPoints = new FreezingAndBoilingPoints();
FreezeAndBoiling freezeAndBoiling = freezeAndBoilingPoints.new FreezeAndBoiling(temperature);
if (freezeAndBoiling.isEthylAlchoolBoiling())
{
System.out.println("Ethyl alcohol will freeze.");
}
if (freezeAndBoiling.isOxygenFreezing())
{
System.out.println("Oxygen will freeze.");
}
if (freezeAndBoiling.isWaterFreezing())
System.out.println("Water will freeze.");
if (freezeAndBoiling.isEthylAlchoolBoiling())
{
System.out.println("Ethyl alcohol will boil.");
}
if (freezeAndBoiling.isOxygenBoiling())
{
System.out.println("Oxygen will boil.");
}
if (freezeAndBoiling.isWaterBoiling())
{
System.out.println("Water will boil.");
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.