The following table lists the freezing and boiling points of several substances.
ID: 671897 • 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
TemperatureDemo.java
package com.temperature;
import java.util.Scanner;
/**
*
* @author Chegg
*/
class Temperature {
protected int Temp;//temperature variable
/**
* Get the value of Temp
*
* @return the value of Temp
*/
public int getTemp() {
return Temp;
}
/**
* Set the value of Temp
*
* @param Temp new value of Temp
*/
public void setTemp(int Temp) {
this.Temp = Temp;
}
public void isEthylefreezing(int Temp)//method
{
if (Temp <= -173) {
System.out.println("isEthylefreezing" + " " + "true");
} else {
System.out.println("isEthylefreezing" + " " + "false");
}
}
public void isEthyleboiling(int Temp)//method
{
if (Temp >= 172) {
System.out.println("isEthyleboiling" + " " + "true");
} else {
System.out.println("isEthyleboiling" + " " + "false");
}
}
public void isWaterfreezing(int Temp)//method
{
if (Temp <= 32) {
System.out.println("isWaterfreezing" + " " + "true");
} else {
System.out.println("isWaterfreezing" + " " + "false");
}
}
public void isWaterboiling(int Temp)//method
{
if (Temp >= 212) {
System.out.println("isWaterboiling" + " " + "true");
} else {
System.out.println("isWaterboiling" + " " + "false");
}
}
public void isOxygenfreezing(int Temp)//method
{
if (Temp <= -362) {
System.out.println("isOxygenboiling" + " " + "true");
} else {
System.out.println("isOxygenboiling" + " " + "false");
}
}
public void isOxygenboiling(int Temp)//method
{
if (Temp >= -306) {
System.out.println("isOxygenboiling" + " " + "true");
} else {
System.out.println("isOxygenboiling" + " " + "false");
}
}
}
public class TemperatureDemo extends Temperature//superclass is Temperature and sub class TemperatureDemo inherits class Temperature thru extends keyword
{
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);//keyboard inputting thru scanner class
System.out.println("enter the temperature");
int Temp = sc.nextInt();
Temperature t = new Temperature();//creating temperature object
t.isEthylefreezing(Temp);
t.isEthyleboiling(Temp);
t.isOxygenfreezing(Temp);
t.isOxygenboiling(Temp);
t.isWaterfreezing(Temp);
t.isWaterboiling(Temp);
}
}
Output
1)
enter the temperature
65
isEthylefreezing false
isEthyleboiling false
isOxygenboiling false
isOxygenboiling true
isWaterfreezing false
isWaterboiling false
BUILD SUCCESSFUL (total time: 4 seconds)
2)
enter the temperature
-264
isEthylefreezing true
isEthyleboiling false
isOxygenboiling false
isOxygenboiling true
isWaterfreezing true
isWaterboiling false
BUILD SUCCESSFUL (total time: 5 seconds)
3)
enter the temperature
-43
isEthylefreezing false
isEthyleboiling false
isOxygenboiling false
isOxygenboiling true
isWaterfreezing true
isWaterboiling false
BUILD SUCCESSFUL (total time: 5 seconds)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.