In java code:
Write a Temperature class that has two private instance variables:
• degrees: a double that holds the temperature value • scale: a character either ‘C’ for Celsius or ‘F’ for Fahrenheit (either in uppercase or lowercase)
The class should have (1) four constructor methods: one for each instance variable (assume zero degrees if no value is specified and assume Celsius if no scale is specified), one with two parameters for the two instance variables, and a no-argument constructor (set to zero degrees Celsius);
(2) two getter methods to return the temperature, one to return the degrees Celsius, the other to return the degrees Fahrenheit – use the following formulas to write the two methods, and round to the nearest tenth of a degree:
degreesC = (degreesF – 32) *5 /9 degreesF = (degreesC *9 /5) + 32
(3) three setter methods, one to set the value, one to set the scale (‘F’, ‘f’, ‘C’, or ‘c’, if any other invalid character is given, terminate your program), and one to set both;
(4) three comparison methods, an equals method to test whether two temperatures are equal, one method to test whether one temperature is greater than another, and one method to test whether one temperature is less than another (note that a Celsius temperature can be equal to a Fahrenheit temperature as indicated by the above formulas). Write a driver program in TemperatureTest that tests each of the constructors, getters, setters, and include at least one true and one false case for each of the comparison methods.
//Temperature.java
class Temperature
{
private
double degrees;
char scale;
//constructors
public
Temperature()
{
degrees=0;
scale='c';
}
Temperature(double deg)
{
degrees=deg;
scale='c';
}
Temperature(char ch)
{
degrees=0;
scale=ch;
}
Temperature(double deg, char ch)
{
degrees=deg;
scale=ch;
}
//getter methods
double getCelcius()
{
return ((degrees-32) * (5/9));
}
double getFahrenheit()
{
return (degrees*(9/5)+32);
}
//setter methods
void setDegrees(double deg)
{degrees=deg;
}
void setScale(char ch)
{
if(ch=='F'||ch=='f'||ch=='c'||ch=='C')
scale=ch;
else
System.exit(0);
}
void setBoth(double deg, char ch)
{degrees=deg;
scale=ch;
}
//comparision methods
boolean equals(Temperature t)
{
double temp;
if(this.degrees==t.degrees)
return true;
else if(this.scale=='c'||this.scale=='C' &&
t.scale=='F'||t.scale=='f')
{
temp=t.getCelcius();
if(this.degrees==temp)
return true;
else
return false;
}
else if(this.scale=='F'||this.scale=='f' &&
t.scale=='c'||t.scale=='C')
{
temp=t.getFahrenheit();
if(this.degrees==temp)
return true;
else
return false;
}
else
return false;
}
boolean lessThan(Temperature t)
{
double temp;
if(this.scale=='c'||this.scale=='C' &&
t.scale=='F'||t.scale=='f')
{
temp=t.getCelcius();
if(this.degrees<=temp)
return true;
else
return false;
}
else if(this.scale=='F'||this.scale=='f' &&
t.scale=='c'||t.scale=='C')
{
temp=t.getFahrenheit();
if(this.degrees<=temp)
return true;
else
return false;
}
else
{
if(this.degrees<=t.degrees)
return true;
else
return false;
}
}
boolean greaterThan(Temperature t)
{
double temp;
if(this.scale=='c'||this.scale=='C' &&
t.scale=='F'||t.scale=='f')
{
temp=t.getCelcius();
if(this.degrees>=temp)
return true;
else
return false;
}
else if(this.scale=='F'||this.scale=='f' &&
t.scale=='c'||t.scale=='C')
{
temp=t.getFahrenheit();
if(this.degrees>=temp)
return true;
else
return false;
}
else
{
if(this.degrees>=t.degrees)
return true;
else
return false;
}
}
}
//Main.java
public class Main{
public static void main(String[] args)
{
Temperature t1=new Temperature(34.5,'c');
Temperature t2=new Temperature(94.5,'f');
if(t1.equals(t2))
System.out.println("t1 temperature equals t2");
else if(t1.lessThan(t2))
System.out.println("t1 temperature less than or equals t2");
else if(t1.greaterThan(t2))
System.out.println("t1 temperature is greater than or equal to
t2");
//Now t1 and t2 objects are assingned with same
values
t2.setDegrees(34.5);
t2.setScale('c');
if(t1.equals(t2))
System.out.println("t1 temperature equals t2");
}
}

In java code: Write a Temperature class that has two private instance variables: • degrees: a...
Java Write a Temperature class that has two private instance variables: • degrees: a double that holds the temperature value • scale: a character either ‘C’ for Celsius or ‘F’ for Fahrenheit (either in uppercase or lowercase) The class should have - four constructor methods: one for each instance variable (assume zero degrees if no value is specified and assume Celsius if no scale is specified), one with two parameters for the two instance variables, and a no-argument constructor (set...
Java program
Write a Temperature class that represents temperatures in degrees in both Celsius and Fahrenheit. Use a floating- point number for the temperature and a character for the scale, eitherでfor Celsius or 'F' for fahrenheit. The class should have Four constructors: one for the number of degrees, one for the scale, one for both the degrees and scale, and a default constructor. For each of these constructors, assume zero degrees if no value is specified and celsius if no...
A breakdown of the problem is as follows: Class name: Temperature Instance variables: temp (double) and tempScale (char; either ‘C’ or ‘F’) Constructor methods: Temperature() – sets temp to 0 Celsius Temperature(double initialTemp) – sets temp Temperature(char tempType) – sets tempScale to ‘C’ or ‘F’) Temperature(double initialTemp, char tempType) -- sets temp and tempScale to ‘C’ or ‘F’) Accessor methods: getTemp – returns value of temp for the object getTempScale– returns temperature scale (‘C’ or...
CIT-111 Homework #4, Part A Chapter 4, problem #7 (pages 254-255) A breakdown of the problem is as follows: Class name: Temperature Instance variables: temp (double) and tempScale (char; either ‘C’ or ‘F’) Constructor methods: Temperature() – sets temp to 0 Celsius Temperature(double initialTemp) – sets temp Temperature(char tempType) – sets tempScale to ‘C’ or ‘F’) Temperature(double initialTemp, char tempType) -- sets temp and tempScale to ‘C’ or ‘F’) Accessor methods: getTemp – returns value of...
Java please The kelvin is the base unit of temperature in the International System of Units (SI), having the unit symbol K. It is named after the Belfast-born, Glasgow University engineer and physicist William Thomson, 1st Baron Kelvin (1824–1907). It uses absolute zero as its null point. The Celsius scale, also known as the centigrade scale, is a temperature scale used by the International System of Units (SI). The Celsius scale is based on 0 °C for the freezing point...
c++ please
2. (50 points) Create a Temperature class that internally stores a temperature in degrees Kelvin as a double. Create mutator functions named setTempKelvin, setTempFahrenheit, and set TempCelsius that take an input temperature in the specified temperature scale (i.e. Kelvin, Fahrenheit, and Celsius, respectively), and convert the temperature to Kelvin, and store that temperature in the class member private variable (only in Kelvin, no other scales). Also, create functions that return the stored temperature in degrees Kelvin, Fahrenheit, or...
Java code for the following inheritance hierarchy figure..
1. Create class Point, with two private
instance variables x and y that represented for the coordinates for
a point.
Provide constructor for initialising two instance variables.
Provide set and get methods
for each instance variable,
Provide toString method to return formatted
string for a point coordinates.
2. Create class Circle, its inheritance from
Point.
Provide a integer private
radius instance variable.
Provide constructor to
initialise the center coordinates and radius for...
Write a Temperature class that will hold a temperature in Fahrenheit, and provide meth- ods to get the temperature in Fahrenheit, Celsius, and Kelvin. The class should have the following field: • ftemp – A double that holds a Fahrenheit temperature. The class should have the following methods: Constructor – The constructor accepts a Fahrenheit temperature (as a double) and stores it in the ftemp field. setFahrenheit – The setFahrenheit method accepts a Fahrenheit temperature (as a double) and stores...
JAVA
Write a class called Pen that contains the following information: 1. Private instance variables for the price of the pen (float) and color of the pen (String). 2. A two-argument constructor to set each of the instance variables above. If the price is negative, throw an IllegalArgumentException stating the argument that is not correct. 3. Get and Set methods for each instance variable with the same error detection as the constructor. public class Pen {
B. Suppose a thermometer reads TC a. Write an expression for how many Fahrenheit degrees there are between 0 and TC. Your expression would give the Fahrenheit temperature if both temperatures had their o" mark at the same place. However, when the Celsius scale reads o', the Fahrenheit scale reads 32°. Write an equation relating the Fahrenheit temperature to the Celsius temperature. Define your variables clearly. b.
B. Suppose a thermometer reads TC a. Write an expression for how many...