Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The following table lists the freezing and boiling points of several substances.

ID: 3820082 • Letter: T

Question

The following table lists the freezing and boiling points of several substances.

Substance

Freezing Point

Alcohol

-173.2

Oxygen

-361.8

Water

32.0

Design a class in JAVA 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:

isAlcoholFreezing. 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.

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.

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.

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. For example, if the temperature is -200.8, the class should report that water will freeze and alcohol will freeze at that temperature.

You need to design a class Temperature, and then demo it in the second file TemperatureDemo.java

Substance

Freezing Point

Alcohol

-173.2

Oxygen

-361.8

Water

32.0

Explanation / Answer


package feezingsubstances;

import java.util.Scanner;

public class FeezingSubstances {

private double temperature;
public FeezingSubstances(double temperature){
this.temperature = temperature;
}
  
public boolean isAlcoholFreezing(){
if(temperature <= -173.2){
return true;
}
return false;
  
}
  
public boolean isOxygenFreezing(){
if(temperature <= -361.8){
return true;
}
return false;
  
}
public boolean isWaterFreezing(){
if(temperature <= 32){
return true;
}
return false;
}
  
//you can use these below classes also to set and get temperature value.
  
// public double getTemperature()
// {
// return temperature;
// }
//
// public void setTemperature()
// {
// this.temperature = temperature;
// }
public static void main(String[] args) {
Scanner inoutTemperature=new Scanner(System.in);
System.out.println("Enter the temperature: ");

FeezingSubstances fz = new FeezingSubstances(inoutTemperature.nextDouble()); //create an instance and pass temperature value to the constructor
  
if( fz.isAlcoholFreezing() || fz.isOxygenFreezing() || fz.isWaterFreezing() ){

if( fz.isAlcoholFreezing() && fz.isOxygenFreezing() && fz.isWaterFreezing() ){
System.out.println("Water, Oxygen and Alcohol will freeze at that temperature");
}
else if(fz.isAlcoholFreezing() && fz.isOxygenFreezing()){
System.out.println("Oxygen and Alcohol will freeze at that temperature");
}
else if( fz.isAlcoholFreezing() && fz.isWaterFreezing() ){
System.out.println("Water and Alcohol will freeze at that temperature");
}
else if( fz.isOxygenFreezing() && fz.isWaterFreezing() ){
System.out.println("Water and Oxygen will freeze at that temperature");
}
else if(fz.isAlcoholFreezing()){
System.out.println("Only Alcohol freezes at that temperature");
}
else if (fz.isOxygenFreezing()){
System.out.println("Only Oxygen freezes at that temperature");
}
else if (fz.isWaterFreezing()){
System.out.println("Only Water freezes at that temperature");
}
else{
System.out.println("None of the substances freeze-200.8 at that temperature");
}

}
  
}
  
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote