JavaDeploy
SiteMap
Readers Writers
Java Streams
Java Programming
Java Language
Java Fundamentals
«Prev
Next»
Java Programming
Java Technology
Useful Technology
Acquiring Java SDK
Java Compiler
Tic Tac Toe Applet
Java Applet Viewer
Java TM Interpreter
Java SDK Conclusion
OO Programming
OO Fundamentals
Understanding Classes
Object Communication
Defining Objects
Adding Behavior Methods
OO Programming Conclusion
OO Programming - Quiz
Java Programs
Java Api
Applications Applets
Java main() method
Static Class Member
Command Line Arguments
Building String Characters
Standard IO Communication
Application Construction
Program Flow
Conditional Branching
Conditional Ternary Operator
Switch Statement
For Loops
foreach Loop
Nested Loops
while Loops
doWhile Loop
Break Statement
Control Flow Conclusion
Programming Fundamentals
Identifiers, Keywords, Literals
Java Comments
Java Data Types
Storing Data Arrays
Manipulating Text
Evaluating Expressions
Numeric Operators
Boolean Assignment Operators
Compound Operators
Java Language Conclusion
Object Classes
Inheritance Fundamentals
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
Modify your
RightTriangle
class by providing two constructors: a default constructor and a detailed constructor that initializes the instance variables
a
and
b
.
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.