CS99 |
Fundamental Programming Concepts
Summer 2001 |
|
Lab
8
|
Overview |
The goals of this lab are to:
|
Part I: Triangle class |
Part A: class Triangle {
/* Constructor */
/* Return the area of the triangle */
/* Return the perimeter of the triangle
*/
/* Returns the angle opposite side a
(in degrees) */
/*
Return the angle opposite side b in degrees */ /*
Return the angle opposite side c in degrees */
/*
Return true if the triangle is a right triangle, false otherwise */ } You should use Math.acos()
in your angle methods. The
description for Math.acos() is acos(double a) Returns
the arc cosine of an angle, in the range of 0.0 through pi. Hence, Math.acos( 0 ) returns pi/2, or 1.5707963267948966. Note that the answer is given in radians. To convert an angle in radians to degrees, one must multiply the angle by (180/pi). (You can use Math.PI for this purpose.) Print and save a copy of your completed Triangle.java. Part B: What is the length of the first side of
your triangle? 5 Pondering. . . . . Your triangle is a right triangle!
Print and save a copy of TriangleTester.java. |
Part II: Playing with numbers |
Here
are two definitions:
Part
A: class NumberTypes { /* Return true if parameter n is a
type B integer Part B: |
Part III: Reversing a String |
Complete the implementation for the String
method reverse below: /* * To test your code, place the method in a class called Reverse.java and use it directly like so: class Reverse { public static void main(
String[] args) { static String reverse(
String s ) { } If you use that particular program to test your method, it should print the alphabet in reverse order on the computer monitor. Save Reverse.java and print it. For your convenience, here are some methods that pertain to strings
|
Part IV: Cramer's Rule |
Write a program that solves a system of two equations using
Cramer's rule. The input will be
the coefficients and constants in the system, and they will all be integers. The
output will be the solution to the system.
Call your program EquationSolver.java. Background: Cramer's Rule Cramer's Rule is a method for solving a system of linear equations.
If you have two equations with variables x and y written as: ax
+ by = c dx
+ ey = f then the solution for x
and y can be found using the following
equations: x
= (ce-bf)/(ae - bd), y = (af - cd)/ (ae - bd). Note that Cramer's rule does not work if the expression (ae
- bd) is equal to zero. We
shall ignore that possibility. Part A: /** Part B: Enter a: 1
The solution to the system of
equations:
1x + 2y = 5 Additional
Requirements
|
Part V: Submit Your Lab |
Hand in printouts for
As
usual, don't forget to put your name, net ID, and date at the
top of each file. This lab is due next Thursday, 26 July 2001 at the beginning of the lab session. That means you have one week to complete this assignment. Hand it in to Siddharth as usual. |