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

JAVA question: Write two programs a class FreezingPoint.java (70 points) and a T

ID: 3723486 • Letter: J

Question

JAVA question:

Write two programs a class FreezingPoint.java (70 points) and a TestFreezingPoint.java (30 points).

Part1:

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

Substance                                              Freezing Point                                       Boiling Point

Ethyl Alcohol                                                 -173                                                      172

Oxygen                                                         -362                                                     -306

Water                                                             32                                                       212

Design a class FreezingPoint.java that stores a temperature in a temperature field and has the appropriate accessor(get) and mutator(set) methods for the field (10 points).

In addition the class should have the following methods:

isEthylFreezing this method 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. (10 points)

isEthylBoiling this method 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. (10 points)

isOxygenFreezing this method 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. (10 points)

isOxygenBoiling this method 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. (10 points)

isWaterFreezing this method 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. (10 points)

isWaterBoiling this method 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. (10 points)

HINT: The snippet below for isEthylFreezing method.

   public boolean isEthylFreezing()

   {

      boolean status;

     

      if (temperature <= -173.0)

         status = true;

      else

         status = false;

        

      return status;

   }

Part2:

TestFreezingPoint.java will ask the user to enter a temperature, and then displays a list of substances that will freeze at that temperature and those that 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. (20 points)

Use while loop. The program continues until the user decides to quit the game (10)

Explanation / Answer

import java.util.*;

class FreezingPoint
{
private double temperature;

//set and get methods
public double getTemperature()
{
return temperature;
}
public void setTemperature(double temperature)
{
this.temperature = temperature;
}

//boolean methods to check if ethyly,oxygen and water is boiling or freezing at the temperaure
public boolean isEthylFreezing()
{
boolean status;
    
      if (temperature <= -173.0)
         status = true;
      else
         status = false;
       
      return status;
}
public boolean isEthylBoiling()
{
boolean status;
    
      if (temperature >= 172.0)
         status = true;
      else
         status = false;
       
      return status;
}

public boolean isOxygenFreezing()
{
boolean status;
    
      if (temperature <= -362.0)
         status = true;
      else
         status = false;
       
      return status;
}
public boolean isOxygenBoiling()
{
boolean status;
    
      if (temperature >= -306.0)
         status = true;
      else
         status = false;
       
      return status;
}
public boolean isWaterFreezing()
{
boolean status;
    
      if (temperature <= 32.0)
         status = true;
      else
         status = false;
       
      return status;
}
public boolean isWaterBoiling()
{
boolean status;
    
      if (temperature >= 212.0)
         status = true;
      else
         status = false;
       
      return status;
}
}
class TestFreezingPoint
{
public static void main (String[] args)
{

Scanner input = new Scanner(System.in);
char choice;
do
{
System.out.println("Enter the temperature : ");
double temperature = input.nextDouble();

FreezingPoint fp = new FreezingPoint();
fp.setTemperature(temperature);

if(fp.isEthylFreezing())
System.out.println(" Ethyl will freeze ");

if(fp.isOxygenFreezing())
System.out.println(" Oxygen will freeze ");

if(fp.isWaterFreezing())
System.out.println(" Water will freeze ");

if(fp.isEthylBoiling())
System.out.println(" Ethyl will boil ");

if(fp.isOxygenBoiling())
System.out.println(" Oxygen will boil ");

if(fp.isWaterBoiling())
System.out.println(" Water will boil ");

System.out.println(" Do you want to quit the game? y/n : ");
choice = input.next().charAt(0);

if(choice == 'y')
break;
}while(choice == 'n');
}
}

Output:

Enter the temperature :-20

Water will freeze

Oxygen will boil

Do you want to quit the game? y/n :n
Enter the temperature :40

Oxygen will boil

Do you want to quit the game? y/n : y