-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpakTemperature.java
83 lines (77 loc) · 2.65 KB
/
pakTemperature.java
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package converterPackage;
/** Class made to refer to for arithmetic process of converting
* between °Celsius and °Fahrenheit scale metrics. */
class Temperature{
/** Variable "reading" used for calculations. */
private double reading = 0;
/** A flag simply to indicate the metric of the value
* stored. Made for testing stages of class.
* False == Fahrenheit. */
private boolean metric = true;
//False == Fahrenheit.
public Temperature(double n){
this.reading = n;
}
/*public Temperature(String a){
FloatInputPad.splitInput(a);
} In case I integrate the text box with the actual splitInput() function. Temporarily here for me to figure out later.*/
/* Just in case I can't set it any other way for some
reason, this sets the temperature value. */
public void setTemperature(double n){
this.reading = n;
}
/* Returns the temperature value. */
public double getTemperature(){
return this.reading;
}
/** The following method processes a number using an
* equation made to convert to °Celsius. */
public double convertToCelsius(double x)
{
/** "meter" is a temporary variable used in this
* class's methods to store conversion results. */
double meter = ((x - 32) / 1.8);
this.reading = meter;
this.metric = true;
return meter;
}
/** Processes the stored value using an equation made to
* convert to °Celsius. */
public double convertToCelsius()
{
double meter = ((this.reading - 32) / 1.8);
this.reading = meter;
this.metric = true;
return meter;
}
/** Processes a number using an equation made to
* convert to °Fahrenheit. */
public double convertToFaren(double x)
{
double meter = (x * 1.8) + 32;
this.reading = meter;
this.metric = false;
return meter;
}
/** Processes the stored value using an equation made to
* convert to °Fahrenheit. */
public double convertToFaren()
{
double meter = (this.reading * 1.8) + 32;
this.reading = meter;
this.metric = false;
return meter;
}
/** Separate method made to set the temperature to
* °Celsius just in case I needed it. */
private void setToCelsius(){
this.metric = true;
//System.out.println("Temperature is now in °Celsius.");
}
/** Separate method made to set the temperature to
* °Fahrenheit just in case I needed it. */
private void setToFaren(){
this.metric = false;
//System.out.println("Temperature is now in °Fahrenheit.");
}
}