-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTemperatureConverter.java
More file actions
47 lines (39 loc) · 944 Bytes
/
TemperatureConverter.java
File metadata and controls
47 lines (39 loc) · 944 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/**
* TemperatureConverter class
* @author Jason Taylor
*/
public class TemperatureConverter {
// hold value to convert
private int tempValue = 0;
public TemperatureConverter() {
this.tempValue = 0;
}
public TemperatureConverter(int value) {
this.tempValue = value;
}
public void setValue(int value) {
this.tempValue = value;
}
public int getValue() {
return this.tempValue;
}
/**
* convert to celcius
* @return double Fahrenheit temperature
*/
public double toCelcius() {
return (this.tempValue - 32) * 5/9;
}
/**
* convert to Fahrenheit
* @return double celcius temperature
*/
public double toFahrenheit() {
return this.tempValue * 9/5 + 32;
}
public static void main(String[] args) {
TemperatureConverter tc = new TemperatureConverter(212);
double boiling = tc.toCelcius();
System.out.println("Boiling water in celcius is " + boiling);
}
}