-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMenuServer.java
76 lines (60 loc) · 2.78 KB
/
MenuServer.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import java.io.*;
import java.net.*;
import java.util.*;
public class EchoServer {
public static void main(String[] args) {
try {
ServerSocket s = new ServerSocket(8189);
Socket incoming = s.accept();
try {
InputStream inStream = incoming.getInputStream();
OutputStream outStream = incoming.getOutputStream();
Scanner in = new Scanner(inStream);
PrintWriter out = new PrintWriter(outStream, true /* autoFlush */);
out.println("Bem vindo!");
out.println("Por favor, selecione uma opcao");
out.println("1 ............ Converter Dolar pra Real");
out.println("2 ............ Converter Celsius em Fahrenheit");
out.println("3 ............ Converter Km em m");
out.println("0 ............ Sair");
out.println(" ");
boolean done = false;
while (!done && in.hasNextLine()) {
String line = in.nextLine();
out.println(" ");
switch (line) {
case "1":
out.println("Digite um valor em Dolar: ");
int dolar = Integer.parseInt(in.nextLine());
out.println(" ");
out.println("Equivale a " + dolar * 5.75 + " reais");
break;
case "2":
out.println("Digite uma temperatura em Celsius: ");
int celsius = Integer.parseInt(in.nextLine());
out.println(" ");
out.println("Equivale a " + (celsius*1.8+32) + " Fahrenheit");
break;
case "3":
out.println("Digite um valor em Km: ");
int km = Integer.parseInt(in.nextLine());
out.println(" ");
out.println("Equivale a " + km * 1000.00 + " metros.");
break;
default:
break;
}
// out.println("Echo: " + line);
// System.out.println(" " + line);
if (line.trim().equals("0")) {
done = true;
}
}
} finally {
incoming.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}