-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCiscosCClass.java
More file actions
173 lines (139 loc) · 5.53 KB
/
Copy pathCiscosCClass.java
File metadata and controls
173 lines (139 loc) · 5.53 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
//------------------------------------------------------------
// Francisco Rogel February 10, 2017
// Description: Problems from ciscos C class but written in Java
//------------------------------------------------------------
public class CiscosCClass {
public static void main(String[] args)
{
System.out.println("Problem 2:");
System.out.println("Printing out Eulers Number: " + eulersNumber());
System.out.println();
System.out.println("Computing PI: " + computePi());
System.out.println();
System.out.println("Value of E raised to Pi: ");
System.out.println(Math.pow(eulersNumber(), computePi()));
System.out.println();
System.out.println("Value of Pi raised to E: ");
System.out.println(Math.pow(computePi(), eulersNumber()));
System.out.println();
whichIsLarger();
System.out.println();
System.out.println("\n\n\nProblem 3:");
System.out.println();
System.out.println("Converting to radians from degrees: ");
sineAndCosine(90);
System.out.println();
System.out.println("\n\n\nProblem 4: ");
System.out.println("This method computes the distance between 2 points");
System.out.println();
distanceBetween2Points(1,3,5,2,6,1);
System.out.println();
distanceBetween2Points(1.1,5.5,2.2,4.4,7.7,3.3);
System.out.println();
System.out.println("Type two 3-Dimensional coordinates:");
System.out.println("*Type in the form (x1,y1,z1) (x2,y2,z3)*");
//String input = "(1,3,5) (2,6,1)";
Scanner scan = new Scanner(System.in);
String input = scan.nextLine();
int x1 = Integer.parseInt(input.substring(1,2));
int y1 = Integer.parseInt(input.substring(3,4));
int z1 = Integer.parseInt(input.substring(5,6));
int x2 = Integer.parseInt(input.substring(9,10));
int y2 = Integer.parseInt(input.substring(11,12));
int z2 = Integer.parseInt(input.substring(13,14));
distanceBetween2Points(x1,y1,z1,x2,y2,z2);
scan.close();
}
//------------------------------------------------------------
// Method that computes Eulers Number
//------------------------------------------------------------
private static double eulersNumber()
{
double e = 1; // first value of Euler is 1 + 1/1! + 1/2!
double f = 1;
for ( int i=1; i <= 10; i++)
{
f = f * (1.0 / i);
e += f;
}
return e; // Euler's Number
}
//------------------------------------------------------------
//------------------------------------------------------------
// Method that computes pi
//------------------------------------------------------------
public static double computePi()
{
double pi = 0;
int count = 10000;
for(int i = 0; i < count; i++)
{
pi += Math.pow(-1,i)/(2*i+1);
}
return pi * 4;
}
//------------------------------------------------------------
//------------------------------------------------------------
// Which number is larger when raised, E^pi or pi^E
// E = Eulers Number
//------------------------------------------------------------
private static void whichIsLarger()
{
if ((Math.pow(eulersNumber(), computePi()) > (Math.pow(computePi(), eulersNumber()))))
System.out.println("E raised to the pi is larger");
else
System.out.println("pi raised to the E is larger");
}
//------------------------------------------------------------
//------------------------------------------------------------
// Method that returns radians when given degrees and then
// computes the sine and cosine of the angle. Then, computes
// the sine squared and cosine squared (should be 1)
//------------------------------------------------------------
private static void sineAndCosine(int degrees)
{
double radians = 0;
double sine = 0;
double cosine = 0;
DecimalFormat decimalFormat = new DecimalFormat("##.#####"); // Specific Format
radians = ((computePi()/180)*degrees);
System.out.println("\nDegrees: " + degrees);
System.out.println("Radians: " + decimalFormat.format(radians));
System.out.println();
sine = Math.sin(radians);
cosine = Math.cos(radians);
System.out.println("Sine of " + decimalFormat.format(radians) + ": " + decimalFormat.format(sine));
System.out.println("Cosine of: " + decimalFormat.format(radians) + ": " + decimalFormat.format(cosine));
double sineRaised2 = Math.pow(sine, 2);
double cosineRaised2 = Math.pow(cosine, 2);
System.out.println();
System.out.println("Sum of sine squared and cosine squared: " + (sineRaised2 + cosineRaised2));
}
//------------------------------------------------------------
//------------------------------------------------------------
// Method that computes the distance between 2 points (x,y,z)
//------------------------------------------------------------
private static void distanceBetween2Points(double a1, double b1, double c1, double a2, double b2, double c2)
{
DecimalFormat decimalFormat = new DecimalFormat("##.#####"); // Specific Format
double distance = 0;
double a1Minusa1 = 0;
double b1Minusb1 = 0;
double c1Minusc1 = 0;
a1Minusa1 = (a1 - a2);
b1Minusb1 = (b1 - b2);
c1Minusc1 = (c1 - c2);
a1Minusa1 = Math.pow(a1Minusa1, 2);
b1Minusb1 = Math.pow(b1Minusb1, 2);
c1Minusc1 = Math.pow(c1Minusc1, 2);
distance = Math.sqrt((a1Minusa1 + b1Minusb1 + c1Minusc1));
System.out.println("Computing the distance between 2 points " + "(" + a1 + "," + b1 + "," + c1 + ") and (" + a2 + "," + b2 + "," + c2 + ")");
System.out.println(decimalFormat.format(distance));
}
//------------------------------------------------------------
}