@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

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.49098984063300843","path":"Main.java","file":{"path":"Main.java","content":{"asEncoding":{"base64":"aW1wb3J0IGphdmEuaW8uKjsKCnB1YmxpYyBjbGFzcyBNYWluIHsKCiAgICBwdWJsaWMgc3RhdGljIHZvaWQgbWFpbihTdHJpbmdbXSBhcmdzKSB0aHJvd3MgSU9FeGNlcHRpb257CiAgICAgICAgQnVmZmVyZWRSZWFkZXIga2V5Ym9hcmQgPSBuZXcgQnVmZmVyZWRSZWFkZXIobmV3IElucHV0U3RyZWFtUmVhZGVyKFN5c3RlbS5pbikpOwoKICAgICAgICBpbnQgb3A7CiAgICAgICAgZG91YmxlIHZhbDsKICAgICAgICBkb3VibGUgcmVzdWx0OwoKICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oIi0tLS0gQ2hvb3NlIHRoZSBjb252ZXJzaW9uIC0tLS0iKTsKICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oIjEgLSBDZWxzaXVzIC0gRmFocmVuaGVpdCIpOwogICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbigiMiAtIEZhaHJlbmhlaXQgLSBDZWxzaXVzIik7CiAgICAgICAgU3lzdGVtLm91dC5wcmludGxuKCIzIC0gUXVpbG9tZXRyb3MgLSBNaWxoYXMiKTsKICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oIjQgLSBNaWxoYXMgLSBRdWlsb21ldHJvcyIpOwoKICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oIlxuLS0tLSBUeXBlIHRoZSBjb252ZXJzaW9uIHlvdSB3YW50IC0tLS0gIik7CiAgICAgICAgb3AgPSBuZXcgSW50ZWdlcihrZXlib2FyZC5yZWFkTGluZSgpKS5pbnRWYWx1ZSgpOwoKCQlTeXN0ZW0ub3V0LnByaW50bG4oIlxuLS0tLSBSZXN1bHQgLS0tLSAiKTsKCiAgICAgICAgc3dpdGNoKG9wKXsKICAgICAgICAgICAgY2FzZSAxOgogICAgICAgICAgICAgICAgU3lzdGVtLm91dC5wcmludGxuKCJDZWxzaXVzOiAiKTsKICAgICAgICAgICAgICAgIHZhbCA9IG5ldyBEb3VibGUoa2V5Ym9hcmQucmVhZExpbmUoKSkuZG91YmxlVmFsdWUoKTsKICAgICAgICAgICAgICAgIHJlc3VsdCA9ICg1LjAvOS4wKSAqICh2YWwtMzIuMCk7CiAgICAgICAgICAgICAgICBTeXN0ZW0ub3V0LnByaW50KCJGYWhyZW5oZWl0OiAiICsgcmVzdWx0KTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIGNhc2UgMjoKICAgICAgICAgICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbigiRmFocmVuaGVpdDogIik7CiAgICAgICAgICAgICAgICB2YWwgPSBuZXcgRG91YmxlKGtleWJvYXJkLnJlYWRMaW5lKCkpLmRvdWJsZVZhbHVlKCk7CiAgICAgICAgICAgICAgICByZXN1bHQgPSAzMi4wICsgdmFsKig5LzUpOwogICAgICAgICAgICAgICAgU3lzdGVtLm91dC5wcmludCgiQ2Vsc2l1czogXG4iICsgcmVzdWx0KTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIGNhc2UgMzoKICAgICAgICAgICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbigiS2lsb21ldGVyczogIik7CiAgICAgICAgICAgICAgICB2YWwgPSBuZXcgRG91YmxlKGtleWJvYXJkLnJlYWRMaW5lKCkpLmRvdWJsZVZhbHVlKCk7CiAgICAgICAgICAgICAgICByZXN1bHQgPSB2YWwgKiAwLjYyMTQ7CiAgICAgICAgICAgICAgICBTeXN0ZW0ub3V0LnByaW50KCJNaWxlczogXG4iICsgcmVzdWx0KTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIGNhc2UgNDoKICAgICAgICAgICAgICAgIFN5c3RlbS5vdXQucHJpbnQoIk1pbGVzOiAiKTsKICAgICAgICAgICAgICAgIHZhbCA9IG5ldyBEb3VibGUoa2V5Ym9hcmQucmVhZExpbmUoKSkuZG91YmxlVmFsdWUoKTsKICAgICAgICAgICAgICAgIHJlc3VsdCA9IHZhbCAvIDAuNjIxNDsKICAgICAgICAgICAgICAgIFN5c3RlbS5vdXQucHJpbnQoIktpbG9tZXRlcnM6IFxuIiArIHJlc3VsdCk7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIH0KCgkJU3lzdGVtLm91dC5wcmludGxuKCJcblxuLS0tLS0tLS0tLS0tLS0tLS0tLS0tICIpOwoJCVN5c3RlbS5vdXQucHJpbnRsbigiVGhhbmtzLCBzZWUgeWEhIik7CgkJU3lzdGVtLm91dC5wcmludGxuKCItLS0tLS0tLS0tLS0tLS0tLS0tLS0gIik7CiAgICB9Cn0="},"asBuffer":null},"loaded":true}}
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("--------------------- ");
    }
}