-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProject_2.java
More file actions
44 lines (37 loc) · 1.8 KB
/
Project_2.java
File metadata and controls
44 lines (37 loc) · 1.8 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
/** This program takes Imperial measurements as input, then converts them and outputs them as Metric measurements.
* @author Logan Murphy
* @version 1.0
*/
//imports
import java.util.Scanner;
import java.text.DecimalFormat;
public class Project_2 {
public static void main(String[] args) {
//new scanner and new decimal format variables
Scanner scnr = new Scanner(System.in);
DecimalFormat df = new DecimalFormat("#.##");
DecimalFormat df0 = new DecimalFormat("0.00");
//starting message
System.out.println("Welcome to Imperial to Metric Conversion Calculator");
//Fahrenheit-Celsius Conversion
System.out.println("Please enter the temperature in degree Fahrenheit:");
double degreesFahrenheit = scnr.nextDouble();
double degreesCelsius = (degreesFahrenheit - 32) * (5.0/9.0);
System.out.println("The temperature in degree Celsius is " + df.format(degreesCelsius) + " C");
//Fluid Ounces-Liters Conversion
System.out.println("Please enter the volume of liquid in fluid ounces:");
double volumeOunces = scnr.nextDouble();
double volumeLiter = (volumeOunces * 29.5735) / 1000;
System.out.println("The volume of the liquid in Liters is " + df.format(volumeLiter) + " L");
//Pounds-Kilograms Conversion
System.out.println("Please enter the weight of an object in pounds:");
double weightPounds = scnr.nextDouble();
double weightKilograms = (weightPounds * 454) / 1000.0;
System.out.println("The weight of an object in kilograms is " + df0.format(weightKilograms) + " Kg");
//Miles-Kilometers Conversion
System.out.println("Please enter the distance to a city in miles:");
double distanceMiles = scnr.nextDouble();
double distanceKilometers = (distanceMiles * 1.609);
System.out.println("The distance to a city in kilometers is " + df.format(distanceKilometers) + " Km");
}
}