Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Triacontakai
- * Just a trig calculator that I may or may not convert to do more stuff than just trig later
- * Can solve for angles and am currently working on solving for triangles.
- * Outputs in DEGREES, I might make this an option later
- */
- import java.util.*;
- public class Trig {
- public static void main(String[] args){
- Scanner lnscan = new Scanner(System.in);
- Scanner optscan = new Scanner(System.in);
- System.out.println("Trig Calculator");
- System.out.println("1) Solve for angle");
- System.out.println("2) Solve for triangle");
- //System.out.println("2) Solve for side");
- int opt = optscan.nextInt();
- if (opt == 1){
- //solve for angle
- System.out.println("1) Sine (O/H)");
- System.out.println("2) Cosine (A/H)");
- System.out.println("3) Tangent (O/A)");
- opt = optscan.nextInt();
- if (opt == 1){
- System.out.println("Enter your side lengths (O/H): ");
- String stemp = lnscan.nextLine();
- String[] sides = stemp.split("/");
- double x = Double.parseDouble(sides[0]);
- double y = Double.parseDouble(sides[1]);
- double ans = Math.toDegrees(Math.asin(x/y));
- System.out.println("Answer: "+ ans);
- }
- else if (opt == 2){
- System.out.println("Enter your side lengths (A/H): ");
- String stemp = lnscan.nextLine();
- String[] sides = stemp.split("/");
- double x = Double.parseDouble(sides[0]);
- double y = Double.parseDouble(sides[1]);
- double ans = Math.toDegrees(Math.acos(x/y));
- System.out.println("Answer: "+ ans);
- }
- else if (opt == 3){
- System.out.println("Enter your side lengths (O/A): ");
- String stemp = lnscan.nextLine();
- String[] sides = stemp.split("/");
- double x = Double.parseDouble(sides[0]);
- double y = Double.parseDouble(sides[1]);
- double ans = Math.toDegrees(Math.acos(x/y));
- System.out.println("Answer: "+ ans);
- }
- else{
- System.out.println("Invalid option!");
- }
- }
- else if (opt == 2){
- //solve for triangle
- int op = 0;
- String aleg = "";
- String oleg = "";
- String hypo = "";
- System.out.println("Enter angle measure: ");
- String ang = lnscan.nextLine();
- if (!ang.isEmpty()){
- op++;
- }
- System.out.println("Enter adjacent leg (if no angle, ignore 'adjacent'): ");
- aleg = lnscan.nextLine();
- if (!aleg.isEmpty()){
- op++;
- }
- if (op < 2){
- System.out.println("Enter opposite leg (if no angle, ignore 'opposite'): ");
- oleg = lnscan.nextLine();
- if (!oleg.isEmpty()){
- op++;
- }
- }
- if (op < 2){
- System.out.println("Enter hypotenuse: ");
- hypo = lnscan.nextLine();
- if (!hypo.isEmpty()){
- op++;
- }
- }
- if (op < 2){
- System.out.println("Enter 2 values please!");
- }
- //START CALCULATIONS HERE
- if (!ang.isEmpty()){
- if (!hypo.isEmpty()){
- double angr = Math.toRadians(Double.parseDouble(ang));
- double adjacent = Double.parseDouble(hypo)*Math.cos(angr);
- double opposite = Double.parseDouble(hypo)*Math.sin(angr);
- double ang2 = 90.0 - Double.parseDouble(ang);
- System.out.println("Inputted angle: "+ ang);
- System.out.println("Hypotenuse: "+ hypo);
- System.out.println("Adjacent: "+ adjacent);
- System.out.println("Opposite: "+ opposite);
- System.out.println("Other angle: "+ ang2);
- }
- if (!aleg.isEmpty()){
- double angr = Math.toRadians(Double.parseDouble(ang));
- double hypotenuse = Double.parseDouble(aleg)/Math.cos(angr);
- double opposite = Double.parseDouble(aleg)*Math.tan(angr);
- double ang2 = 90.0 - Double.parseDouble(ang);
- System.out.println("Inputted angle: "+ ang);
- System.out.println("Hypotenuse: "+ hypotenuse);
- System.out.println("Adjacent: "+ aleg);
- System.out.println("Opposite: "+ opposite);
- System.out.println("Other angle: "+ ang2);
- }
- if (!oleg.isEmpty()){
- double angr = Math.toRadians(Double.parseDouble(ang));
- double hypotenuse = Double.parseDouble(oleg)/Math.sin(angr);
- double adjacent = Double.parseDouble(oleg)/Math.tan(angr);
- double ang2 = 90.0 - Double.parseDouble(ang);
- System.out.println("Inputted angle: "+ ang);
- System.out.println("Hypotenuse: "+ hypotenuse);
- System.out.println("Adjacent: "+ adjacent);
- System.out.println("Opposite: "+ oleg);
- System.out.println("Other angle: "+ ang2);
- }
- }
- else{
- if (!oleg.isEmpty() && !aleg.isEmpty()){
- double ang1 = Math.atan(Double.parseDouble(oleg)/Double.parseDouble(aleg));
- double hypotenuse = Double.parseDouble(oleg)/Math.sin(ang1);
- ang1 = Math.toDegrees(ang1);
- double ang2 = 90.0 - ang1;
- System.out.println("Main angle: "+ ang1);
- System.out.println("Hypotenuse: "+ hypotenuse);
- System.out.println("Adjacent: "+ aleg);
- System.out.println("Opposite: "+ oleg);
- System.out.println("Other angle: "+ ang2);
- }
- if (!oleg.isEmpty() && !hypo.isEmpty()){
- double ang1 = Math.asin(Double.parseDouble(oleg)/Double.parseDouble(hypo));
- double adjacent = Double.parseDouble(hypo)*Math.cos(ang1);
- ang1 = Math.toDegrees(ang1);
- double ang2 = 90.0 - ang1;
- System.out.println("Main angle: "+ ang1);
- System.out.println("Hypotenuse: "+ hypo);
- System.out.println("Adjacent: "+ adjacent);
- System.out.println("Opposite: "+ oleg);
- System.out.println("Other angle: "+ ang2);
- }
- if (!aleg.isEmpty() && !hypo.isEmpty()){
- double ang1 = Math.acos(Double.parseDouble(aleg)/Double.parseDouble(hypo));
- double opposite = Double.parseDouble(hypo)*Math.sin(ang1);
- ang1 = Math.toDegrees(ang1);
- double ang2 = 90.0 - ang1;
- System.out.println("Main angle: "+ ang1);
- System.out.println("Hypotenuse: "+ hypo);
- System.out.println("Adjacent: "+ aleg);
- System.out.println("Opposite: "+ opposite);
- System.out.println("Other angle: "+ ang2);
- }
- }
- /*System.out.println("Do you have an angle? Y/N")
- char yn = optscan.next().charAt(0);
- switch(yn){
- case y: System.out.println("State angle measure: ");
- case n: System.out.println("State your first side in the format (H/L:Measure): ");
- String stemp = lnscan.nextLine();
- String[] sides = stemp.split(":");
- String s1type = sides[0];
- String s1meas = sides[1];
- case default: System.out.println("Invalid option!");*/
- /*System.out.println("1) Sine (O/H)");
- System.out.println("2) Cosine (A/H)");
- System.out.println("3) Tangent (O/A)");
- opt = optscan.nextInt();
- if (opt == 1){
- }
- else if (opt == 2){
- }
- else if (opt == 3){
- }
- else{
- System.out.println("Invalid option!");
- }*/
- }
- else{
- System.out.println("Invalid option!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement