CS 1054: Laboratory Exercise 5

Objective

This exercise's objective is to get you some more experience in writing methods and using methods from the Math class.

To Receive Credit

Show the work that you do to the GTA.

Activities

Exercise 1 (4.13 from textbook): After launching the Eclipse IDE, create a new project and name it Lab51. Create a class within this project called MyTriangle that contains the following methods.

public static boolean isValid(double side1, double side2, double side3)
Returns true if the sum of any two sides is greater than the third side.
public static double area(double side1, double side2, double side3)
Returns the area of the triangle. The forumla for computing the area is

Within the main method, write code that reads three sides for a triangle and computes the area if the input is valid. Otherwise, display that the input is invalid.

Exercise 2 (4.14 from textbook): Print the following table to display the sin value and cos value of degrees from 0 to 360 in increments of 10 degrees. Round the value to keep four digits after the decimal point. You can do this in the main method of the previous class or create a new class called Lab52.

Degree    Sin     Cos
0         0.0     1.0
10        0.1736  0.9848
...
350       -0.1736 0.9848
360       0.0     1.0


© Mir Farooq Ali 2005.