Thread: Triangle
View Single Post
  #1 (permalink)  
Old 01-13-2008, 10:17 PM
jkswebsite jkswebsite is offline
Member
 
Join Date: Nov 2007
Location: Illinois
Posts: 12
jkswebsite has a little shameless behaviour in the past
Send a message via AIM to jkswebsite
Triangle
Quote:
* Write a class called Triangle.
*
* A triangle must have three int values for its side lengths.
* These private fields MUST have names a, b, and c.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* THE FOLLOWING METHODS AND CONSTRUCTORS MUST APPEAR IN THIS ORDER! *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Write a default constructor that creates an
* equilateral Triangle with side length 1.0
*
* Write another constructor that takes three int parameters that
* will be the three side lengths. It must validate
* the three parameters that they can actually form a triangle.
* (recall from Geometry: the sum of any two sides
* of a triangle must be greater than the third side)
* The constructor must throw an IllegalArgumentException
* if the parameters are invalid.
*
* Write a method called getLongestSide that takes no parameters
* and returns the value of the longest side length.
* (i.e. the greatest of a,b, and c)
*
* Write a method called isRightTriangle that takes no parameters
* and returns true if the Triangle, (whose sides are a,b, and c)
* form a right triangle and returns false otherwise.
* (hint: use Pythagorean Theorem and recall the longest side is the hypotenuse)
*
* Write a method called scalar that takes an int parameter and
* converts this Triangle to a similar Triangle by multiplying
* each side length by the parameter.
*
* ~~BONUS~~
* Write a method called isCongruentTo that takes a Triangle parameter
* and returns true if all three 'corresponding' sides are equal,
* and returns false otherwise.
* (example: 3,4,5 is congruent to 3,5,4 but not congruent to 3,3,5)
*
* ~~BONUS~~
* Write a method called area that returns the area of this Triangle
*
*/

... (over) ...

/**
* TriangleRunner should produce the following output shown below
*/

public class TriangleRunner {
public static void main(String args[]) {

Triangle t1 = new Triangle();
Triangle t2 = new Triangle(3,4,5);
Triangle t3 = new Triangle(4,6,3);
System.out.println(t1.longestSide());
System.out.println(t2.longestSide());
System.out.println(t3.longestSide());
System.out.println(t1.isRightTriangle());
System.out.println(t2.isRightTriangle());
System.out.println(t3.isRightTriangle());
t1.scalar(10);
t2.scalar(10);
t3.scalar(10);
System.out.println(t1.longestSide());
System.out.println(t2.longestSide());
System.out.println(t3.longestSide());
System.out.println(t1.isRightTriangle());
System.out.println(t2.isRightTriangle());
System.out.println(t3.isRightTriangle());
Triangle t4 = new Triangle(3,9,4);
}
}

/*
output:
1
5
6
false
true
false
10
50
60
false
true
false
Exception in thread "main" java.lang.IllegalArgumentException: cannot form a tri
angle with values 3,9,4
*/
That is out assignment, and I have a template and some basic starting code, but could someone walk me through it? My aim is Jkk088. I'll be on all day. Thanks so much, I really appreciate it.
__________________
Jonathan - AIM: JKK088
Reply With Quote
Sponsored Links