Question
Asked by:
mahsan
mahsan
Rating : No Rating
Questions Asked: 9
Tutorials Posted: 0
 

$10.00 Java small coding in 2 class: Triangle and TestTriangle

Q:
Triangle class
a) Use lengths of sides as attributes. Alternatively use co-ordinates of corners. data types to be used ( String, double, int)
b) Code a constructor that takes three lengths as inputs
c) Code a second constructor that takes one length as input (equilateral).
d) Code a third constructor that has no inputs and sets the lengths as 3,4,5
e) Code methods to get perimeter and get length of sides
f) Code a method to set length of sides

The Triangle class should have a TriangleTest driver class to run it. In this class build at least 3 Triangle objects, one per constructor and run all methods at least once to test that the methods work at least once.
 


   
   
   
   
 
Available Tutorials to this Question
Posted by:
b_h
b_h
Rating (671): A+
Questions Asked: 0
Tutorials Posted: 1188, earned $24,653.40
 

$10.00 Java Programming Help - Triangle and TestTriangle - Code and Explanation

  • This tutorial was purchased 1 time and rated A+ by students like you.
  • Posted on May 22, 2008 at 10:14:22PM
A:
Preview: ... 2 = s2;<br> side3 = s3;<br> }<br></pre><br><br>Then we can compute the perimeter, which is just the sum of the sides, by this simple method:<br><pre><br> // return the perimeter of the triangle (sum of side lengths)<br> public double perimeter() {<br> return side1 + side2 + side3;<br> }<br><br></pre><br><br>The methods to get and set the the side lengths are simple and almost identical to each other. Here's what we'd write for the first side ...

The full tutorial is about 273 words long plus attachments.

Attachments:
TriangleTest.java (1K) (Preview)
Triangle.java (0K) (Preview)
Posted by:
modulo51
modulo51
Rating (110): A-
Questions Asked: 1
Tutorials Posted: 353, earned $2,117.64
 

$9.00 Triangle.java; TriangleTest.java w/ all constructors and methods tested

  • This tutorial hasn't been purchased yet.
  • Posted on May 22, 2008 at 10:44:45PM
A:
Preview: ... Length() {<br> Triangle D = new Triangle();<br> System.out.println(<br> "\\nNo argument constructor");<br> System.out.println("Lengths (default):\\n" +<br> "a: " + D.getSides()[0] + "\\n" +<br> "b: " + D.getSides()[1] + "\\n" +<br> "c: " + D.getSides()[2] +<br> "\\nPerimeter: " + D.getPerimeter());<br> }<br><br> static void demoMethods() {<br> System.out.println(<br> "\\nDemonstration of get and set methods:");<br> System.out.println("Set sides at 11, 13, and 17:");<br> Triangle E = new Triangle();<br> E.setSides(11, 13, 17);<br> System ...

The full tutorial is about 984 words long plus attachments.

Attachments:
TriangleTest.java (1K) (Preview)
Triangle.java (1K) (Preview)
   
Join Now or Log In
Get Tutoring
Get Paid
Academic Honesty