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 to zero degrees Celsius);
- 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
- 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;
- 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.
class Temparature {
private double temp;
private char scale;
public Temparature(double aTemp, char aC) {
super();
temp = aTemp;
scale = aC;
}
public Temparature() {
super();
temp = 0;
scale = 'C';
}
public Temparature(double aTemp) {
super();
temp = aTemp;
scale = 'C';
}
public Temparature(char s) {
super();
temp = 0;
scale = s;
}
public double getTemp() {
return temp;
}
public void setTemp(double aTemp) {
temp = aTemp;
}
public char getScale() {
return scale;
}
public void setScale(char aScale) {
scale = aScale;
}
public double getDegreesC() {
if(scale=='C')
return
temp;
return 5 * (temp - 32) / 9.0;
}
public double getDegreesF() {
if(scale=='F')
return
temp;
return 9.0 * (temp / 5.0) +
32;
}
public boolean equals(Temparature t) {
return t.getTemp() ==
this.getTemp();
}
public boolean greater(Temparature t) {
return (this.temp >
t.temp);
}
public boolean lessThan(Temparature t) {
return (this.temp <
t.temp);
}
public String toString() {
temp += 0.05;
String t = temp + "";
t = t.substring(0, t.indexOf(".") +
2);
return t + " " + scale;
}
}
public class TemparatureTest {
public static void main(String[] args) {
Temparature t = new
Temparature(104, 'F');
System.out.println(t.getDegreesC());
System.out.println(t.getDegreesF());
}
}

Note : Please comment below if you have concerns. I am here to help you
If you like my answer please rate and help me it is very Imp for me
Java Write a Temperature class that has two private instance variables: • degrees: a double that...
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...
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...
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 {
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...
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...