Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.text.DecimalFormat;
- /**
- *
- * @author Kayton
- */
- public class SimplePhysCalc {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) throws IOException {
- // TODO code application logic here
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
- double[] mag = new double[4];
- double[] angle = new double[4];
- double[] cos = new double[4];
- double[] sin = new double[4];
- double[] cos1 = new double[4];
- double[] sin1 = new double[4];
- DecimalFormat df = new DecimalFormat("0.000");
- System.out.println("Please enter vector magnitude 0: ");
- mag[0] = Double.parseDouble(br.readLine());
- System.out.println("Please enter angle 0: ");
- angle[0] = Double.parseDouble(br.readLine());
- System.out.println("");
- cos[0] = Math.cos(Math.toRadians(angle[0]));
- sin[0] = Math.sin(Math.toRadians(angle[0]));
- System.out.println("Please enter vector magnitude 1: ");
- mag[1] = Double.parseDouble(br.readLine());
- System.out.println("Please enter angle 1: ");
- angle[1] = Double.parseDouble(br.readLine());
- System.out.println("");
- cos[1] = Math.cos(Math.toRadians(angle[1]));
- sin[1] = Math.sin(Math.toRadians(angle[1]));
- System.out.println("Please enter vector magnitude 2: ");
- mag[2] = Double.parseDouble(br.readLine());
- System.out.println("Please enter angle 2: ");
- angle[2] = Double.parseDouble(br.readLine());
- System.out.println("");
- cos[2] = Math.cos(Math.toRadians(angle[2]));
- sin[2] = Math.sin(Math.toRadians(angle[2]));
- System.out.println("Please enter vector magnitude 3: ");
- mag[3] = Double.parseDouble(br.readLine());
- System.out.println("Please enter angle 3: ");
- angle[3] = Double.parseDouble(br.readLine());
- System.out.println("");
- cos[3] = Math.cos(Math.toRadians(angle[3]));
- sin[3] = Math.sin(Math.toRadians(angle[3]));
- System.out.println(mag[0] + "*cos(" + angle[0] + ") = " + mag[0] + "*(" + df.format(cos[0]) + ") = " + df.format(mag[0] * cos[0]));
- System.out.println(mag[0] + "*sin(" + angle[0] + ") = " + mag[0] + "*(" + df.format(sin[0]) + ") = " + df.format(mag[0] * sin[0]));
- System.out.println(mag[1] + "*cos(" + angle[1] + ") = " + mag[1] + "*(" + df.format(cos[1]) + ") = " + df.format(mag[1] * cos[1]));
- System.out.println(mag[1] + "*sin(" + angle[1] + ") = " + mag[1] + "*(" + df.format(sin[1]) + ") = " + df.format(mag[1] * sin[1]));
- System.out.println(mag[2] + "*cos(" + angle[2] + ") = " + mag[2] + "*(" + df.format(cos[2]) + ") = " + df.format(mag[2] * cos[2]));
- System.out.println(mag[2] + "*sin(" + angle[2] + ") = " + mag[2] + "*(" + df.format(sin[2]) + ") = " + df.format(mag[2] * sin[2]));
- System.out.println(mag[3] + "*cos(" + angle[3] + ") = " + mag[3] + "*(" + df.format(cos[3]) + ") = " + df.format(mag[3] * cos[3]));
- System.out.println(mag[3] + "*sin(" + angle[3] + ") = " + mag[3] + "*(" + df.format(sin[3]) + ") = " + df.format(mag[3] * sin[3]));
- System.out.println("");
- System.out.println("Because I don't have the graph, the signs may not be \n"
- + "correct on the calculations above. If you wish to invert\n"
- + "the sign of any of the numbers, do it manually in the next\n"
- + "set of calculations");
- System.out.println("");
- System.out.println("I will now combine all of the cosine values. I can \n"
- + "take in a maximum of 4 values. Please enter the desired values\n"
- + "above with their proper signs: (separate with enter, use 0's\n"
- + "if no value is desired)");
- cos1[0] = Double.parseDouble(br.readLine());
- cos1[1] = Double.parseDouble(br.readLine());
- cos1[2] = Double.parseDouble(br.readLine());
- cos1[3] = Double.parseDouble(br.readLine());
- double totCos = 0;
- for (double i : cos1) {
- totCos += i;
- }
- System.out.println("The total cosine value is " + df.format(totCos));
- System.out.println("");
- System.out.println("I will now combine all of the sine values. I can \n"
- + "take in a maximum of 4 values. Please enter the desired values\n"
- + "above with their proper signs: (separate with enter, use 0's\n"
- + "if no value is desired)");
- sin1[0] = Double.parseDouble(br.readLine());
- sin1[1] = Double.parseDouble(br.readLine());
- sin1[2] = Double.parseDouble(br.readLine());
- sin1[3] = Double.parseDouble(br.readLine());
- double totSin = 0;
- for (double i : sin1) {
- totSin += i;
- }
- System.out.println("The total sine value is " + df.format(totSin));
- System.out.println("");
- System.out.println("The total magnitude of the resultant vector is " + df.format(Math.sqrt((totSin*totSin) + (totCos*totCos))));
- double totTan = totSin/totCos;
- System.out.println("Tangent = Sine/cosine = (" + df.format(totSin) + ")/(" + df.format(totCos) + ") = " + df.format(totSin/totCos));
- System.out.println("The angle of the resultant vector is " + df.format(Math.toDegrees(Math.atan(totTan))) + " degrees.");
- }
- }
Add Comment
Please, Sign In to add comment