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
122
Java Programs
Java Api
Applications Applets
Java main() method
Static Class Member
Command Line Arguments
Building String Characters
Standard IO Communication
Application Construction
122
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
Using Instance Variables Methods - Exercise
Objective:
Use instance variables and methods.
Exercise Grading
The full credit for this exercise is 5 points. To receive full credit, you will need to successfully create the source code for the class and test program. You will submit your source code by pressing the submit button.
Exercise Instructions
Create a class named
RightTriangle
which models a right triangle. Use two instance variables named
a
and
b
to represent the lengths of the shorter sides of the right triangle, and use an instance method
hypotenuse()
to calculate the length of the hypotenuse of the right triangle. The length of the hypotenuse is equal to the square root of the sum of the squares of the lengths of the shorter sides.
Write a test application called
TriangleTest
that creates an instance of the
RightTriangle
class, sets the values of the instance variables
a
and
b
to 3.0 and 4.0 respectively, and then invokes 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
5.0
.
What to submit
In the text box below, cut and paste the source code for
RightTriangle
and
TriangleTest
. Click the Submit Button after pasting your source code .