-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTemperature.java
More file actions
73 lines (65 loc) · 2.55 KB
/
Temperature.java
File metadata and controls
73 lines (65 loc) · 2.55 KB
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
// Sukhamrit Singh
// Temperature
/*
This program will read a Celsius degree in a
double value from the console, and then convert
it to Fahrenheit. The result will be displayed
formatted to two decimal places along with a
message. If the temperature in Fahrenheit is
less than 65 degrees, print the message "Please
wear a coat." If the temperature in Fahrenheit
is 65 to 75 degrees, print "It is perfect weather."
Otherwise, print the message "Please bring a
swimsuit."
*/
// Imports the scanner library for user input
import java.util.Scanner;
public class Temperature {
public static void main(String[] args) {
// Loop to keep getting user input
while (true) {
// Creating the scanner variable
Scanner input = new Scanner(System.in);
// Displays text to enter degrees Celsius
System.out.print("Enter a degree in Celsius: ");
// Variable defining the scanner object
double inputtedDegrees = input.nextDouble();
// Variable turning user input into Fahrenheit
double intoFahrenheit = (9.0 / 5) * inputtedDegrees + 32;
/*
If statement displaying messages depending on
the degrees fahrenheit
*/
if (intoFahrenheit < 65) {
/*
Displays the degrees into fahrenheit and
clothing message
*/
System.out.print(inputtedDegrees + " ");
System.out.printf("Celsius is %.2f", intoFahrenheit);
System.out.println(" Fahrenheit");
System.out.println("Please wear a coat.");
} else if (intoFahrenheit > 75) {
/*
Displays the degrees into fahrenheit and
clothing message
*/
System.out.print(inputtedDegrees + " ");
System.out.printf("Celsius is %.2f", intoFahrenheit);
System.out.println(" Fahrenheit");
System.out.println("Please bring a swimsuit.");
} else {
/*
Displays the degrees into fahrenheit and
clothing message
*/
System.out.print(inputtedDegrees + " ");
System.out.printf("Celsius is %.2f", intoFahrenheit);
System.out.println(" Fahrenheit");
System.out.println("It is perfect weather.");
}
// Displays an empty line
System.out.println("");
}
}
}