The following table lists the freezing and boiling points of several substances.
ID: 671615 • 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.
***HAS TO BE IN JAVA***
Substance Freezing Point Boiling Point Ethyl Alcohol -173 172 Oxygen -362 -306 Water 32 212Explanation / Answer
Substance.java:
package com.sample.test;
public class Substance
{
double temperature;
// Constructor
public Substance(double tem) {
temperature = tem;
}
// Set temperature Method
public void setTemperature(double tem)
{
temperature = tem;
}
// Get Temperature method
public double getTemperature()
{
return temperature;
}
// The isEthylFreezing method returns whether or not temperature is at or
// below freezing.
public boolean isEthylFreezing()
{
return (temperature <= -173 ? true : false);
}
// The isEthylBoiling method returns whether or not temperature is at or
// above boiling.
public boolean isEthylBoiling()
{
return (temperature >= 172 ? true : false);
}
// The isOxygen nFreezing method returns whether or not temperature is at or
// below freezing.
public boolean isOxygenFreezing()
{
return (temperature <= -362 ? true : false);
}
// The isOxygenBoiling method returns whether or not temperature is at or
// above boiling.
public boolean isOxygenBoiling()
{
return (temperature >= -306 ? true : false);
}
// The isWaterFreezing method returns whether or not temperature is at or
// below freezing.
public boolean isWaterFreezing()
{
return (temperature <= 32 ? true : false);
}
// The isWaterBoiling method returns whether or not temperature is at or
// above boiling.
public boolean isWaterBoiling()
{
return (temperature >= 212 ? true : false);
}
} // end of Substance Class
Temperature.java:
package com.sample.test;
import java.util.Scanner;
public class Temperature
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.print("What is the the temperature? ");
double temperature = sc.nextDouble();
Substance substance1 = new Substance(temperature);
if (substance1.isEthylFreezing()) {
System.out.println("Ethyl alcohol will freeze");
}
if (substance1.isOxygenFreezing()) {
System.out.println("Oxygen will freeze");
}
if (substance1.isWaterFreezing()) {
System.out.println("Water will freeze");
}
if (substance1.isEthylBoiling()) {
System.out.println("Ethyl alcohol will boil");
}
if (substance1.isOxygenBoiling()) {
System.out.println("Oxygen will boil");
}
if (substance1.isWaterBoiling()) {
System.out.println("Water will Boil");
}
sc.close();
}
}
Output:
Run at 1st time
What is the the temperature? 65
Oxygen will boil
Run at 2nd time
What is the the temperature? -264
Ethyl alcohol will freeze
Water will freeze
Oxygen will boil
Run at 3rd time:
What is the the temperature? -43
Water will freeze
Oxygen will boil
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.