//Shawnak Shivakumar
//
//December 22, 2020
//
//This program gives the missing info in a triangle using tangents, cosines, sin, arcs, radians, and degrees.
//
//VIEWERS - COPY AFTER THIS LINE TILL THE END AND PASTE IT HERE:
//https://www.onlinegdb.com/. Select Java As the language and click run! Enter your //numbers into the console and enjoy!
import java.util.*;
public class Main {
public static void main(String args[]){
Scanner scan = new Scanner(System.in);
System.out.println("Enter 1 if you want to run the Using Sin, Cos, Tan To Find Missing Lengths of Triangle Program, or 2 is you don't!");
int ans = scan.nextInt();
Scanner in = new Scanner(System.in);
while (ans != 2) {
System.out.println("This program uses Right Triangle △ABC, where <B = 90* and AC is the hypotenuse.");
System.out.println("Please enter EXACTLY 2 information (excluding the b = 90*), if you do not know the number, type 0.");
System.out.println("<A = ");
float a = scan.nextFloat();
while (a >= 90) {
System.out.println("This number is invalid. Angle a has to be less than 90*. Try again. <A = ");
a = scan.nextFloat();
}
System.out.println("<B = 90*");
float b = 90;
if (a > 0) {
System.out.println("Side AC = ");
float AC = scan.nextFloat();
if (AC > 0) {
float c = 90 - a;
float AB = AC * (float) Math.sin(c*Math.PI/180);
float BC = (float) Math.sqrt((float) Math.pow(AC,2) - (float) Math.pow(AB,2));
float ABrounded = (float) Math.round(AB*100.0)/100;
float BCrounded = (float) Math.round(BC*100.0)/100;
System.out.println("Results: Angle A = " + a);
System.out.println("Angle B = 90");
System.out.println("Angle C = " + c);
System.out.println("AC = " + AC);
System.out.println("AB = " + ABrounded);
System.out.println("BC = " + BCrounded);
}
else {
System.out.println("Side AB = ");
float AB = scan.nextFloat();
if (AB > 0) {
float c = 90 - a;
AC = AB / (float) Math.cos(a*Math.PI/180);
float ACrounded = (float) Math.round(AC*100.0)/100;
float BC = (float) Math.sqrt((float) Math.pow(AC,2) - (float) Math.pow(AB,2));
float BCrounded = (float) Math.round(BC*100.0)/100;
System.out.println("Results: Angle A = " + a);
System.out.println("Angle B = 90");
System.out.println("Angle C = " + c);
System.out.println("AC = " + ACrounded);
System.out.println("AB = " + AB);
System.out.println("BC = " + BCrounded);
}
else {
System.out.println("Side BC = ");
float BC = scan.nextFloat();
float c = 90 - a;
AC = BC / (float) Math.cos(c * Math.PI/180);
float ACrounded = (float) Math.round(AC*100.0)/100;
AB = (float) Math.sqrt((float) Math.pow(AC,2) - (float) Math.pow(BC,2));
float ABrounded = (float) Math.round(AB*100.0)/100;
System.out.println("Results: Angle A = " + a);
System.out.println("Angle B = 90");
System.out.println("Angle C = " + c);
System.out.println("AC = " + ACrounded);
System.out.println("AB = " + ABrounded);
System.out.println("BC = " + BC);
}
}
}
else if (a <= 0) {
System.out.println("<C = ");
float c = scan.nextFloat();
while (c >= 90) {
System.out.println("This number is invalid. Angle c has to be less than 90*. Try again. <C = ");
c = scan.nextFloat();
}
if (c > 0) {
System.out.println("Side AC = ");
float AC = scan.nextFloat();
if (AC > 0) {
a = 90 - c;
float AB = AC * (float) Math.sin(c*Math.PI/180);
float BC = (float) Math.sqrt((float) Math.pow(AC,2) - (float) Math.pow(AB,2));
float ABrounded = (float) Math.round(AB*100.0)/100;
float BCrounded = (float) Math.round(BC*100.0)/100;
System.out.println("Results: Angle A = " + a);
System.out.println("Angle B = 90");
System.out.println("Angle C = " + c);
System.out.println("AC = " + AC);
System.out.println("AB = " + ABrounded);
System.out.println("BC = " + BCrounded);
}
else {
System.out.println("Side AB = ");
float AB = scan.nextFloat();
if (AB > 0) {
a = 90 - c;
AC = AB / (float) Math.sin(c*Math.PI/180);
float BC = (float) Math.sqrt((float) Math.pow(AC,2) - (float) Math.pow(AB,2));
float ACrounded = (float) Math.round(AC*100.0)/100;
float BCrounded = (float) Math.round(BC*100.0)/100;
System.out.println("Results: Angle A = " + a);
System.out.println("Angle B = 90");
System.out.println("Angle C = " + c);
System.out.println("AC = " + ACrounded);
System.out.println("AB = " + AB);
System.out.println("BC = " + BCrounded);
}
else {
System.out.println("Side BC = ");
float BC = scan.nextFloat();
AC = BC / (float) Math.cos(c * Math.PI/180);
float ACrounded = (float) Math.round(AC*100.0)/100;
AB = (float) Math.sqrt((float) Math.pow(AC,2) - (float) Math.pow(BC,2));
float ABcrounded = (float) Math.round(AB*100.0)/100;
a = 90 - c;
System.out.println("Results: Angle A = " + a);
System.out.println("Angle B = 90");
System.out.println("Angle C = " + c);
System.out.println("AC = " + ACrounded);
System.out.println("AB = " + ABcrounded);
System.out.println("BC = " + BC);
}
}
}
else if (c <= 0) {
System.out.println("Side AC = ");
float AC = scan.nextFloat();
if (AC > 0) {
System.out.println("Side AB = ");
float AB = scan.nextFloat();
if (AB > 0) {
float BC = (float) Math.sqrt((float) Math.pow(AC,2) - (float) Math.pow(AB,2));
float BCrounded = (float) Math.round(BC*100.0)/100;
c = (float) Math.toDegrees(Math.asin(AB/AC));
float crounded = (float) Math.round(c*100.0)/100;
a = 90 - crounded;
System.out.println("Results: Angle A = " + a);
System.out.println("Angle B = 90");
System.out.println("Angle C = " + crounded);
System.out.println("AC = " + AC);
System.out.println("AB = " + AB);
System.out.println("BC = " + BCrounded);
}
else {
System.out.println("Side BC = ");
float BC = scan.nextFloat();
AB = (float) Math.sqrt((float) Math.pow(AC,2) - (float) Math.pow(BC,2));
float ABrounded = (float) Math.round(AB*100.0)/100;
c = (float) Math.toDegrees(Math.asin(AB/AC));
float crounded = (float) Math.round(c*100.0)/100;
a = 90 - crounded;
System.out.println("Results: Angle A = " + a);
System.out.println("Angle B = 90");
System.out.println("Angle C = " + crounded);
System.out.println("AC = " + AC);
System.out.println("AB = " + ABrounded);
System.out.println("BC = " + BC);
}
}
else {
System.out.println("Side AB = ");
float AB = scan.nextFloat();
System.out.println("Side BC = ");
float BC = scan.nextFloat();
AC = (float) Math.sqrt((float) Math.pow(AB,2) + (float) Math.pow(BC,2));
c = (float) Math.toDegrees(Math.asin(AB/AC));
float crounded = (float) Math.round(c*100.0)/100;
a = 90 - crounded;
System.out.println("Results: Angle A = " + a);
System.out.println("Angle B = 90");
System.out.println("Angle C = " + crounded);
System.out.println("AC = " + AC);
System.out.println("AB = " + AB);
System.out.println("BC = " + BC);
}
}
}
else {
System.out.println("Sorry! You failed to enter 2 numbers (excluding b = 90*).") ;
}
System.out.println("Do you want to run again, 1 if yes, 2 if no.");
ans = scan.nextInt();
}
}
}