Problem Description: In this project you will develop a program that utilizes a
ID: 3702285 • Letter: P
Question
Problem Description: In this project you will develop a program that utilizes a Temperature class that models a Temperature entity. You need to write a Temperature class as defined in the following UML diagram: This Temperature class will have a field called fTemp, which will hold a Fahrenheit temperature. It will also have two named constants (FREEZING_POINT and BOILING_POINT) that hold the temperature at which water boils (212.0F) and freezes (32.0F) on the Fahrenheit scale. This Temperature class will have a noargument constructor method that will place a default 0.0 value into the fTemp data field. It will have a getter and setter method for the fTemp field. It will also have several service methods. • A method that calculates and returns the fTemp to the Celsius scale. • A method that calculates and returns the fTemp to the Kelvin scale. • A method that returns the Fahrenheit freezing point for water • A method that returns the Fahrenheit boiling point for water • A method that returns True or False if the fTemp is at or above the boiling point. • A method that returns True or False if the fTemp is at or below the freezing point. The formula to convert a Fahrenheit temperature to a Celsius temperature is as follows: Celsius = (5.0 / 9.0) x (Fahrenheit temperature – 32) The formula to convert a Fahrenheit temperature to a Kelvin temperature is as follows: Kelvin = ((5.0 / 9.0) x (Fahrenheit temperature – 32)) + 273 Temperature - FREEZING_POINT : double - BOILING_POINT : double - fTemp: double + Temperature() + setFTemp( fahrenheitTemp : double) : void + getFTemp() : double + getCelsius() : double + getKelvin() : double + getFreezingPoint() : double + getBoilingPoint() : double + isTemperatureBoiling() : boolean + isTemperatureFreezing() : boolean Page 2 of 3 After writing the Temperature class, write a demo/driver program, called TemperatureDemo that demonstrates a temperature object created from the Temperature class. The actions in the demo/driver program’s main method need to be the following: • create a Temperature object using an object instantiation statement that passes no arguments to the constructor method; you may name the object’ reference variable temperature • using a Scanner object ask the user for a Fahrenheit temperature • set the temperature object’s fTemp value by calling the setter method and passing to it the Fahrenheit temperature entered by the user. • call the temperature object’s getCelsius() method and display the returned Celsius value as follows: Temperature 32.0F converted to Celsius is: 0.0C • call the temperature object’s getKelvin() method and display the returned Kelvin value as follows: Temperature 32.0F converted to Kelvin is: 273.0K • call the temperature object’s getBoilingPoint() method to get the Fahrenheit boiling point temperature and display the returned temperature at which water boils as follows: Water boils at: 212.0F • call the temperature object’s getFreezingPoint() method to get the Fahrenheit freezing point temperature and display the returned temperature at which water freezes as follows: Water boils at: 32.0F • call the temperature object’s isTemperatureBoiling() method and if the returned value is true display the following; otherwise display nothing. NOTE: the fTemp value is 235.0F The temperature of 235.0F is at or above boiling. • call the temperature object’s isTemperatureBoiling() method and if the returned value is true display the following; otherwise display nothing. NOTE: the fTemp value is 12.0F The temperature of 12.0F is at or below freezing. NOTE: Don’t forget to include Documentation comments: o file header comments for both java source code files o variable comments for variables in all methods in the demo/driver program o javadoc comments for each of the methods in the Temperature class.
Example Execution: First Example: Enter the Fahrenheit temperature: 325.6 Temperature 325.6F converted to Celsius is: 163.1C Temperature 325.6F converted to Kelvin is: 436.1K Water boils at: 212.0F Water freezes at: 32.0F The temperature of 325.6F is at or above boiling. Second Example: Enter the Fahrenheit temperature: 0 Temperature 0.0F converted to Celsius is: -17.8C Temperature 0.0F converted to Kelvin is: 255.2K Water boils at: 212.0F Water freezes at: 32.0F The temperature of 0.0F is at or below freezing.
Explanation / Answer
Temperature.java
public class Temperature {
//Declaring instance variables
private double fTemp;
//Declaring constants
final double FREEZING_POINT = 212.0;
final double BOILING_POINT = 32.0;
//Zero argumented constructor
public Temperature() {
this.fTemp = 0.0;
}
// getters and setters
public double getfTemp() {
return fTemp;
}
public void setfTemp(double fTemp) {
this.fTemp = fTemp;
}
public double toCelsius() {
return (fTemp - 32) * 5.0 / 9.0;
}
// This method will convert fahrenheit to Kelvin
public double toKelvin() {
return ((5.0 / 9.0) * (fTemp - 32)) + 273;
}
public double getFreezingPoint() {
return FREEZING_POINT;
}
public double getBoilingPoint() {
return BOILING_POINT;
}
public boolean isTemperatureBoiling() {
if (fTemp > BOILING_POINT)
return true;
else
return false;
}
public boolean isTemperatureFreezing() {
if (fTemp < FREEZING_POINT)
return true;
else
return false;
}
}
_________________
Test.java
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
/*
* Creating an Scanner class object which is used to get the inputs
* entered by the user
*/
Scanner sc = new Scanner(System.in);
//Creating an instance of Temperature class
Temperature temperature = new Temperature();
//Getting the input entered by the user
System.out.print("Enter the Fahrenheit temperature:");
double fTemp = sc.nextDouble();
temperature.setfTemp(fTemp);
System.out.printf("Temperature %.1fF converted to Celsius is: %.1fC ", fTemp, temperature.toCelsius());
System.out.printf("Temperature %.1fF converted to Kelvin is: %.1fC ", fTemp, temperature.toKelvin());
System.out.printf("Water boils at: %.1fF ", temperature.getBoilingPoint());
System.out.printf("Water freezes at: %.1fF ", temperature.getFreezingPoint());
if (temperature.isTemperatureBoiling()) {
System.out.printf("The temperature of %.1fF is at or above boiling ", fTemp);
}
if (temperature.isTemperatureFreezing()) {
System.out.printf("The temperature of %.1fF is at or below freezing ", fTemp);
}
}
}
____________________
Output:
Enter the Fahrenheit temperature:325.6
Temperature 325.6F converted to Celsius is: 163.1C
Temperature 325.6F converted to Kelvin is: 436.1C
Water boils at: 32.0F
Water freezes at: 212.0F
The temperature of 325.6F is at or above boiling
___________________
Output#2:
Enter the Fahrenheit temperature:0
Temperature 0.0F converted to Celsius is: -17.8C
Temperature 0.0F converted to Kelvin is: 255.2C
Water boils at: 32.0F
Water freezes at: 212.0F
The temperature of 0.0F is at or below freezing
_____________Thank You
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.