Talk:Java Training Course/JT06: Difference between revisions

From tehowiki
Jump to navigation Jump to search
imported>Gfis
Created page with "The implementation of class ''Rational'' shows many essential features of the Java language: * the difference between <code>static</code> and member methods and properties, *..."
 
imported>Gfis
No edit summary
 
Line 1: Line 1:
The implementation of class ''Rational'' shows many essential features of the Java language:
===Observations===
The implementation of class ''Rational'' shows many important features of the Java language:
* the difference between <code>static</code> and member methods and properties,
* the difference between <code>static</code> and member methods and properties,
* the conditional expression operator <code>condition ? true-value : false-value</code>,
* the conditional expression operator <code>condition ? true-value : false-value</code>,
* <code>this</code>, the reference to the current object
* <code>this</code>, the reference to the current object,
* documentaton comments, to be used for <code>javadoc</code>,


===Test Results===
<pre>
<pre>
georg@nunki:~/work/project/bekasi/jtc$ java Rational 1 1/2 2/3 3/4 4/5 -25/6 -16/7
0/1 + 1/2 = 1/2
0/1 - 1/2 = -1/2
0/1 * 1/2 = 0
0/1 / 1/2 = 0
max(0/1, 1/2) = 1/2
min(0/1, 1/2) = 0
isInteger(0/1) = true
intValue (0/1) = 0
1/2 + 2/3 = 7/6
1/2 - 2/3 = -1/6
1/2 * 2/3 = 1/3
1/2 / 2/3 = 3/4
max(1/2, 2/3) = 2/3
min(1/2, 2/3) = 1/2
isInteger(1/2) = false
intValue (1/2) = 0
2/3 + 3/4 = 17/12
2/3 - 3/4 = -1/12
2/3 * 3/4 = 1/2
2/3 / 3/4 = 8/9
max(2/3, 3/4) = 3/4
min(2/3, 3/4) = 2/3
isInteger(2/3) = false
intValue (2/3) = 0
3/4 + 4/5 = 31/20
3/4 - 4/5 = -1/20
3/4 * 4/5 = 3/5
3/4 / 4/5 = 15/16
max(3/4, 4/5) = 4/5
min(3/4, 4/5) = 3/4
isInteger(3/4) = false
intValue (3/4) = 0
4/5 + -25/6 = -101/30
4/5 - -25/6 = 149/30
4/5 * -25/6 = -10/3
4/5 / -25/6 = -24/125
max(4/5, -25/6) = 4/5
min(4/5, -25/6) = -25/6
isInteger(4/5) = false
intValue (4/5) = 0
-25/6 + -16/7 = -271/42
-25/6 - -16/7 = -79/42
-25/6 * -16/7 = 200/21
-25/6 / -16/7 = 175/96
max(-25/6, -16/7) = -16/7
min(-25/6, -16/7) = -25/6
isInteger(-25/6) = false
intValue (-25/6) = -4


</pre>
</pre>

Latest revision as of 08:26, 25 September 2017

Observations

The implementation of class Rational shows many important features of the Java language:

  • the difference between static and member methods and properties,
  • the conditional expression operator condition ? true-value : false-value,
  • this, the reference to the current object,
  • documentaton comments, to be used for javadoc,

Test Results

georg@nunki:~/work/project/bekasi/jtc$ java Rational 1 1/2 2/3 3/4 4/5 -25/6 -16/7
0/1 + 1/2 = 1/2
0/1 - 1/2 = -1/2
0/1 * 1/2 = 0
0/1 / 1/2 = 0
max(0/1, 1/2) = 1/2
min(0/1, 1/2) = 0
isInteger(0/1) = true
intValue (0/1) = 0

1/2 + 2/3 = 7/6
1/2 - 2/3 = -1/6
1/2 * 2/3 = 1/3
1/2 / 2/3 = 3/4
max(1/2, 2/3) = 2/3
min(1/2, 2/3) = 1/2
isInteger(1/2) = false
intValue (1/2) = 0

2/3 + 3/4 = 17/12
2/3 - 3/4 = -1/12
2/3 * 3/4 = 1/2
2/3 / 3/4 = 8/9
max(2/3, 3/4) = 3/4
min(2/3, 3/4) = 2/3
isInteger(2/3) = false
intValue (2/3) = 0

3/4 + 4/5 = 31/20
3/4 - 4/5 = -1/20
3/4 * 4/5 = 3/5
3/4 / 4/5 = 15/16
max(3/4, 4/5) = 4/5
min(3/4, 4/5) = 3/4
isInteger(3/4) = false
intValue (3/4) = 0

4/5 + -25/6 = -101/30
4/5 - -25/6 = 149/30
4/5 * -25/6 = -10/3
4/5 / -25/6 = -24/125
max(4/5, -25/6) = 4/5
min(4/5, -25/6) = -25/6
isInteger(4/5) = false
intValue (4/5) = 0

-25/6 + -16/7 = -271/42
-25/6 - -16/7 = -79/42
-25/6 * -16/7 = 200/21
-25/6 / -16/7 = 175/96
max(-25/6, -16/7) = -16/7
min(-25/6, -16/7) = -25/6
isInteger(-25/6) = false
intValue (-25/6) = -4