Results 1 to 7 of 7
 09182014, 07:46 AM #1Member
 Join Date
 Sep 2014
 Posts
 5
 Rep Power
 0
Need help using the MATH class for an assignment
Here is the assignment:
Prompt the user to input two sides (a and b) of a right triangle. Calculate, using the
formulas below, the hypotenuse and the other two angles of the triangle. Calculate the
perimeter and the area.
Here are the formulas:
a^2 + b^2 = h^2
sinθ = a/h
A + B + C = 180 degrees
I really just need help on how to start this program out, i know which math classes i need to use. I need help creating the formulas.Last edited by jlcarrillo; 09192014 at 06:30 AM.
 09182014, 07:57 AM #2Nub
 Join Date
 Sep 2014
 Location
 Houston
 Posts
 8
 Rep Power
 0
Re: Need help using the MATH class for an assignment
What have you written out thus far?
There are many ways to solve these.
Don't forget the code tags. =)
 09182014, 07:59 AM #3
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,422
 Blog Entries
 7
 Rep Power
 28
Re: Need help using the MATH class for an assignment
There's only one math class, and it's named Math; it has a bunch of static methods; e.g. Math.sin(x) returns the sine of angle x (measured in radians). Read its API documentation for the details.
kind regards,
JosBuild a wall around Donald Trump; I'll pay for it.
 09182014, 08:09 AM #4
Re: Need help using the MATH class for an assignment
jlcarrillo, you didn't bother to return to the earlier thread you started. Is history going to repeat itself here?
dbIf you're forever cleaning cobwebs, it's time to get rid of the spiders.
 09192014, 05:52 AM #5Member
 Join Date
 Sep 2014
 Posts
 5
 Rep Power
 0
Re: Need help using the MATH class for an assignment
Java Code:import java.util.Scanner; import java.text.DecimalFormat; public class RightTriangle { public static void main(String[] args) { Scanner input = new Scanner(System.in); DecimalFormat df = new DecimalFormat("0.000"); double side_A, side_B, angle_A, angle_B, hypotenuse; final double right_Angle = 90.0; System.out.print("Please enter length of side a: "); side_A = input.nextDouble(); System.out.print("Please enter length of side b: "); side_B = input.nextDouble(); System.out.printf("Side A = %6s\n",df.format(side_A)); System.out.printf("Side B = %6s\n",df.format(side_B)); hypotenuse = Math.sqrt(side_A*side_A+side_B*side_B); angle_A = Math.asin(side_B/hypotenuse)*180/Math.PI; angle_B = right_Angleangle_A; System.out.printf("Hypotenuse = %6s\n",df.format(hypotenuse)); System.out.printf("Angle A = %6s\n",df.format(angle_A)); System.out.printf("Angle B = %6s\n",df.format(angle_B)); System.out.printf("Angle C = %6s\n",df.format(right_Angle)); } }
 09192014, 06:30 AM #6Member
 Join Date
 Sep 2014
 Posts
 5
 Rep Power
 0
Re: Need help using the MATH class for an assignment
I was able to figure it out here is my result:
Java Code:import java.util.Scanner; import java.text.DecimalFormat; public class RightTriangle { public static void main(String[] args) { Scanner input = new Scanner(System.in); DecimalFormat df = new DecimalFormat("0.000"); double side_A, side_B, angle_A, angle_B, hypotenuse, triangle_Area, triangle_Perimeter; final double right_Angle = 90.0; System.out.print("Please enter length of side a: "); side_A = input.nextDouble(); System.out.print("Please enter length of side b: "); side_B = input.nextDouble(); System.out.printf("Side a = %6s\n",df.format(side_A)); System.out.printf("Side b = %6s\n",df.format(side_B)); hypotenuse = Math.sqrt(side_A*side_A+side_B*side_B); angle_A = Math.asin(side_B/hypotenuse)*180/Math.PI; angle_B = right_Angleangle_A; System.out.printf("Hypotenuse = %6s\n",df.format(hypotenuse)); System.out.printf("Angle A = %6s\n",df.format(angle_A)); System.out.printf("Angle B = %6s\n",df.format(angle_B)); System.out.printf("Angle C = %6s\n",df.format(right_Angle)); triangle_Area = side_A*side_B/2; System.out.printf("Area = %6s\n",df.format(triangle_Area)); triangle_Perimeter = side_A+side_B+Math.sqrt(side_A*side_A+side_B*side_B); System.out.printf("Perimeter = %6s\n",df.format(triangle_Perimeter)); input.close(); } }
 09192014, 08:42 AM #7
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,422
 Blog Entries
 7
 Rep Power
 28
Similar Threads

Back to the math class....
By Lionlev in forum Advanced JavaReplies: 11Last Post: 10312012, 08:19 PM 
help with math class and random numbers
By NestorPrime in forum New To JavaReplies: 9Last Post: 10012011, 09:57 PM 
Math Class
By ritwik07 in forum New To JavaReplies: 2Last Post: 09142009, 04:06 PM 
Math class question
By shendel in forum New To JavaReplies: 1Last Post: 03052009, 12:06 PM 
Math Class (ceil, floor, abs)
By Java Tip in forum Java TipReplies: 0Last Post: 12132007, 09:21 AM
Bookmarks