8
8
* @author Tharun S.M.
9
9
*/
10
10
11
- public class TemperatureConversion {
11
+ public
12
+ class TemperatureConversion {
12
13
/*
13
14
* Object of DecimalFormat Class
14
15
* to round the output to 2 decimal point value
15
16
*/
16
- private static final DecimalFormat rnd = new DecimalFormat ("0.00" );
17
+ private
18
+ static final DecimalFormat rnd = new DecimalFormat ("0.00" );
17
19
/*
18
20
* Main method
19
21
*
20
22
* @param args Command line arguments
21
23
*/
22
24
23
- public static void main (String [] args ) {
25
+ public
26
+ static void main (String [] args ) {
24
27
25
28
Scanner sc = new Scanner (System .in );
26
29
@@ -47,16 +50,16 @@ public static void main(String[] args) {
47
50
if (fromType == toType ) {
48
51
System .out .println ("Your Temperature is the same !!" );
49
52
} else if (fromType == 1 && toType == 2 ) {
50
- System .out .println (
51
- "Converted value: " + rnd .format (convertCelsiusToFahrenheit (inTemp )) +
52
- " °F" );
53
+ System .out .println ("Converted value: " +
54
+ rnd .format (convertCelsiusToFahrenheit (inTemp )) +
55
+ " °F" );
53
56
} else if (fromType == 1 && toType == 3 ) {
54
57
System .out .println ("Converted value: " +
55
58
rnd .format (convertCelsiusToKelvin (inTemp )) + " K" );
56
59
} else if (fromType == 2 && toType == 1 ) {
57
- System .out .println (
58
- "Converted value: " + rnd .format (convertFahrenheitToCelsius (inTemp )) +
59
- " °C" );
60
+ System .out .println ("Converted value: " +
61
+ rnd .format (convertFahrenheitToCelsius (inTemp )) +
62
+ " °C" );
60
63
} else if (fromType == 2 && toType == 3 ) {
61
64
System .out .println ("Converted value: " +
62
65
rnd .format (convertFahrenheitToKelvin (inTemp )) + " K" );
@@ -69,6 +72,7 @@ public static void main(String[] args) {
69
72
} else {
70
73
System .out .println ("Please check your input and output types" );
71
74
}
75
+ sc .close ();
72
76
}
73
77
74
78
/**
@@ -77,7 +81,8 @@ public static void main(String[] args) {
77
81
* @param param float paramter
78
82
* @return double
79
83
*/
80
- private static double convertKelvinToCelsius (float inTemp ) {
84
+ private
85
+ static double convertKelvinToCelsius (float inTemp ) {
81
86
82
87
double result = 0 ;
83
88
result = inTemp - 273.15 ;
@@ -90,7 +95,8 @@ private static double convertKelvinToCelsius(float inTemp) {
90
95
* @param param float paramter
91
96
* @return double
92
97
*/
93
- private static double convertKelvinToFahrenheit (float inTemp ) {
98
+ private
99
+ static double convertKelvinToFahrenheit (float inTemp ) {
94
100
95
101
double result = 0 ;
96
102
result = (inTemp * 1.8 ) - 459.67 ;
@@ -103,7 +109,8 @@ private static double convertKelvinToFahrenheit(float inTemp) {
103
109
* @param param float paramter
104
110
* @return double
105
111
*/
106
- private static double convertFahrenheitToKelvin (float inTemp ) {
112
+ private
113
+ static double convertFahrenheitToKelvin (float inTemp ) {
107
114
108
115
double result = 0 ;
109
116
result = (inTemp + 459.67 ) / 1.8 ;
@@ -116,7 +123,8 @@ private static double convertFahrenheitToKelvin(float inTemp) {
116
123
* @param param float paramter
117
124
* @return double
118
125
*/
119
- private static double convertFahrenheitToCelsius (float inTemp ) {
126
+ private
127
+ static double convertFahrenheitToCelsius (float inTemp ) {
120
128
121
129
double result = 0 ;
122
130
result = (inTemp - 32 ) / 1.8 ;
@@ -129,7 +137,8 @@ private static double convertFahrenheitToCelsius(float inTemp) {
129
137
* @param param float paramter
130
138
* @return double
131
139
*/
132
- private static double convertCelsiusToFahrenheit (float inTemp ) {
140
+ private
141
+ static double convertCelsiusToFahrenheit (float inTemp ) {
133
142
134
143
double result = 0 ;
135
144
result = (inTemp * 1.8 ) + 32 ;
@@ -142,7 +151,8 @@ private static double convertCelsiusToFahrenheit(float inTemp) {
142
151
* @param param float paramter
143
152
* @return double
144
153
*/
145
- private static double convertCelsiusToKelvin (float inTemp ) {
154
+ private
155
+ static double convertCelsiusToKelvin (float inTemp ) {
146
156
147
157
double result = 0 ;
148
158
result = inTemp + 273.15 ;
0 commit comments