@rpichioli/

Java temperature and distance conversion app

Java

Terminal Java application to convert temperature degree scales Fahrenheit and Celsius, and distance metrics between Kilometers and Miles

fork
loading
Files
  • Main.java
Main.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
import java.io.*;

public class Main {

    public static void main(String[] args) throws IOException{
        BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));

        int op;
        double val;
        double result;

        System.out.println("---- Choose the conversion ----");
        System.out.println("1 - Celsius - Fahrenheit");
        System.out.println("2 - Fahrenheit - Celsius");
        System.out.println("3 - Quilometros - Milhas");
        System.out.println("4 - Milhas - Quilometros");

        System.out.println("\n---- Type the conversion you want ---- ");
        op = new Integer(keyboard.readLine()).intValue();

		System.out.println("\n---- Result ---- ");

        switch(op){
            case 1:
                System.out.println("Celsius: ");
                val = new Double(keyboard.readLine()).doubleValue();
                result = (5.0/9.0) * (val-32.0);
                System.out.print("Fahrenheit: " + result);
            break;
            case 2:
                System.out.println("Fahrenheit: ");
                val = new Double(keyboard.readLine()).doubleValue();
                result = 32.0 + val*(9/5);
                System.out.print("Celsius: \n" + result);
            break;
            case 3:
                System.out.println("Kilometers: ");
                val = new Double(keyboard.readLine()).doubleValue();
                result = val * 0.6214;
                System.out.print("Miles: \n" + result);
            break;
            case 4:
                System.out.print("Miles: ");
                val = new Double(keyboard.readLine()).doubleValue();
                result = val / 0.6214;
                System.out.print("Kilometers: \n" + result);
            break;
        }

		System.out.println("\n\n--------------------- ");
		System.out.println("Thanks, see ya!");
		System.out.println("--------------------- ");
    }
}