-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEx3.java
More file actions
138 lines (102 loc) · 2.63 KB
/
Ex3.java
File metadata and controls
138 lines (102 loc) · 2.63 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/**
Esse programa calcula o seno, cosseno, tangente e cotangente. Pergunta ao usuario quantos angulos ele quer digitar,
em seguida armazena instancias de classe AnguloObj em um array, preenchido pelo usuário por meio do
teclado.
tratando as excessoes necessarias
Exemplos de entradas e saida:
> Digite a medida em graus do 1º angulo:
30
> Digite a medida em graus do 2º angulo:
45
Resultado =====================
Arco: 0,52
Seno: 0,50
Cosseno: 0,87
Tangente: 0,58
Cotangente: 1,73
Arco: 0,79
Seno: 0,71
Cosseno: 0,71
Tangente: 1,00
Cotangente: 1,00
**/
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.IOException;
public class Ex3
{
public static void main(String[] args) {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String linha=null;
try
{
System.out.println("Digite o numero de angulos:");
linha = reader.readLine();
int qtd_angulos = Integer.parseInt(linha);
AnguloObj[] angulos = new AnguloObj[qtd_angulos];
System.out.println("\n");
for(int i=0; i < angulos.length; i++)
{
String linha_grau=null;
try
{
System.out.println("Digite a medida em graus do "+ (i+1) + "º angulo:");
linha_grau = reader.readLine();
double grau = Double.parseDouble(linha_grau);
angulos[i] = new AnguloObj(grau);
}
catch(NumberFormatException ex)
{
System.out.println("\n"+linha_grau+" nao pode ser convertido em double.");
return;
}
}
System.out.println("\nResultado =====================");
for(AnguloObj angulo: angulos)
{
System.out.println(angulo);
}
}
catch(NumberFormatException ex)
{
System.out.println("\n"+linha+" nao pode ser convertido em inteiro.");
return;
}
catch(IOException ex)
{
System.out.println("Ocorreu um erro de I/O durante a leitura");
}
}
}
class AnguloObj
{
private double arcoRad;
public AnguloObj(double graus)
{
this.arcoRad = Math.toRadians(graus);
}
public double funcaoSeno()
{
return Math.sin(arcoRad);
}
public double funcaoCosseno()
{
return Math.cos(arcoRad);
}
public double funcaoTangente()
{
return Math.tan(arcoRad);
}
public double funcaoCotangente()
{
return 1.0/(funcaoTangente());
}
public String toString()
{
return "Arco: " + String.format("%.2f", arcoRad) + "\n" +
"Seno: " + String.format("%.2f", funcaoSeno()) + "\n" +
"Cosseno: " + String.format("%.2f", funcaoCosseno()) + "\n" +
"Tangente: " + String.format("%.2f", funcaoTangente()) + "\n" +
"Cotangente: " + String.format("%.2f", funcaoCotangente()) + "\n";
}
}