ft office is expired. Editing in Word has been disabled Buy HACC: Central Pennsy
ID: 3783375 • Letter: F
Question
ft office is expired. Editing in Word has been disabled Buy HACC: Central Pennsylvania's Community College Name CPS 230 Assignment #1 Methods Review Fahringer write a program that will input the lengths of the two legs of a triangle using Dialog Boxes. Then calculate the hypotenuse and the six trig functions for one of the angles of the triangle. Display all information in a Message Box. All calculations should be done using Methods. Your program should be well documented both internally and externally. Internal Documentation 3 Use of Methods Efficient coding Correctness of Program 7 Input (GUI's) Output (GUI's)Explanation / Answer
1. Solution to first question(Triangle):
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class Triangle {
public static void main(String[] args){
String fl;
fl = JOptionPane.showInputDialog("Enter First Leg of Traingle"); // input using dialog box
int s1 =Integer.parseInt(fl);// first leg
String sl;
sl = JOptionPane.showInputDialog("Enter Second Leg of Traingle");
int s2 =Integer.parseInt(sl);// second Leg
double h = Math.sqrt(Math.pow(s1, 2) + Math.pow(s2, 2));// Calculating hypotenuse
double degs = 90d;// right angle of traingle
double rads = Math.toRadians(degs);//converting degrees to radians
double sinA = Math.sin(rads);//sine
double cosecA = 1.0/Math.sin(rads);//cosecant
double cosA = Math.cos(rads);//cosine
double secA = 1.0/Math.cos(rads);//secant
double tanA = Math.tan(rads);//tangent
double cotanA = 1.0/Math.tan(rads);//cotangent
String out = "Hypotenuese is " +h + " "+
"Trigonometric functions for right angle(90 degrees) of traingle are: "+
" "+" " +"Sine = "+ sinA+
" "+" " +"Cosecant = "+ cosecA+
" "+" " +"Cosine = "+ cosA+
" "+" " +"Secant = "+ secA+
" "+" " +"Tangent = "+ tanA+
" "+" " +"Cotangent = "+ cotanA;
JOptionPane.showMessageDialog(null, out);//outputting result using message box
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.