117k views
5 votes
Design a class that stores a temperature in a temperature field and has the appropriate accessor and mutator methods for the field. In addition to appropriate constructors, the class should have the following methods:

a. 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.
b. isEthylBoiling. This method should 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.
c. 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.
d. isOxygenBoiling. Thismethod should return the boolean value true if the temperature storedin temperature field is at or above the boiling point of oxygen. Otherwise,the method should return false.
e. 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.
f. 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.

1 Answer

5 votes

Final Answer:

To accomplish this task, I've created a Temperature class in Python with methods to determine if various substances freeze or boil at a given temperature. The program prompts the user for a temperature input and displays the substances that will freeze or boil at that temperature.

```python

class Temperature:

def __init__(self, temp):

self.temperature = temp

def isEthylFreezing(self):

return self.temperature <= -173

def isEthylBoiling(self):

return self.temperature >= 172

def isOxygenFreezing(self):

return self.temperature <= -362

def isOxygenBoiling(self):

return self.temperature >= -306

def isWaterFreezing(self):

return self.temperature <= 32

def isWaterBoiling(self):

return self.temperature >= 212

# Taking user input for temperature

user_temp = float(input("Enter the temperature in Celsius: "))

temp = Temperature(user_temp)

# Checking and displaying substances that will freeze or boil at the entered temperature

if temp.isEthylFreezing():

print("Ethyl alcohol will freeze at this temperature.")

if temp.isEthylBoiling():

print("Ethyl alcohol will boil at this temperature.")

if temp.isOxygenFreezing():

print("Oxygen will freeze at this temperature.")

if temp.isOxygenBoiling():

print("Oxygen will boil at this temperature.")

if temp.isWaterFreezing():

print("Water will freeze at this temperature.")

if temp.isWaterBoiling():

print("Water will boil at this temperature.")

```

Step-by-step explanation:

The Python class `Temperature` contains methods (`isEthylFreezing`, `isEthylBoiling`, `isOxygenFreezing`, `isOxygenBoiling`, `isWaterFreezing`, `isWaterBoiling`) to determine whether various substances freeze or boil at a given temperature. The freezing and boiling points for ethyl alcohol, oxygen, and water are compared to the input temperature to determine their state at that specific temperature. User input is taken for the temperature in Celsius.

The program then checks each substance's freezing and boiling points against the entered temperature and prints the corresponding messages indicating whether each substance will freeze or boil at that specific temperature. This approach ensures the user gets information about which substances are affected by the entered temperature.

User Stephen Darlington
by
8.0k points