Java Fundamentals  «Prev  Next»

Add Java Constructor - Exercise

Adding a constructor

Objective: Add a constructor to the RightTriangle class.

Exercise grading

The full credit for this exercise is 5 points. To receive full credit, you will need to successfully modify the source code for the class definition and test program. You will submit your modified source code to the course tutors.

Exercise Instructions

  1. Modify your RightTriangle class by providing two constructors: a default constructor and a detailed constructor that initializes the instance variables a and b.
  2. Modify your test application, TriangleTest, to create an instance of the RightTriangle class using the detailed constructor with lengths 5.0 and 12.0. Then invoke the hypotenuse() method to calculate the length of the hypotenuse. Make sure that you output the results of hypotenuse() so that you can tell if the class works properly. You should see a result of 13.0.

What to submit

In the text box below, cut and paste the modified source code for RightTriangle and TriangleTest.
Click the Submit Button to submit your source code.