<< Chapter < Page | Chapter >> Page > |
Beginning of the ColMatrixEquals01 program class
At this point, I will put the discussion of the updated GM2D03 library on hold and explain the ColMatrixEquals01 program.
Listing 4 presents the beginning of the ColMatrixEquals01 program class including the beginning of the main method.
Listing 4 . Beginning of the ColMatrixEquals01 class. |
---|
public class ColMatrixEquals01{
public static void main(String[]args){
GM2D03.ColMatrix matA =new GM2D03.ColMatrix(1.5,-2.6);
GM2D03.ColMatrix matB =new GM2D03.ColMatrix(1.5,-2.6);
GM2D03.ColMatrix matC =new GM2D03.ColMatrix(1.500001,-2.600001);
GM2D03.ColMatrix matD =new GM2D03.ColMatrix(1.50001,-2.60001);
System.out.println(matA.equals(matA));System.out.println(matA.equals(matB));
System.out.println(matA.equals(matC));System.out.println(matA.equals(matD)); |
Listing 4 instantiates four different ColMatrix objects and then compares them in different ways, displaying the results of the comparisonson the command-line screen.
Screen output from the program named ColMatrixEquals01
The first four lines of text in Figure 1 were produced by the code in Listing 4. (The remaining output shown in Figure 1 was produced by the code in Listing 5 , which I will explain shortly.)
Figure 1 . Screen output from the program named ColMatrixEquals01. |
---|
true
truetrue
falsetrue
truefalse
truetrue
false |
Because of the simplicity of the code in Listing 4 , you shouldn't need any help in understanding why the code in Listing 4 produced the first four lines of output in Figure 1 .
The third and fourth lines of output in Figure 1 are the result of comparing two matrices whose values are almost equal but not absolutely equal.
Remainder of the ColMatrixEquals01 class
The remainder of the program named ColMatrixEquals01 is shown in Listing 5 . The output produced by this code is shown in the last six lines of text in Figure 1 .
Listing 5 . Remainder of the ColMatrixEquals01 class. |
---|
GM2D03.Point pointA = new GM2D03.Point(
new GM2D03.ColMatrix(15.6,-10.11));GM2D03.Point pointB = new GM2D03.Point(
new GM2D03.ColMatrix(15.6,-10.11));GM2D03.Point pointC = new GM2D03.Point(
new GM2D03.ColMatrix(-15.6,10.11));System.out.println(/*Blank line*/);
System.out.println(pointA.equals(pointA));System.out.println(pointA.equals(pointB));
System.out.println(pointA.equals(pointC));GM2D03.Vector vecA = new GM2D03.Vector(new GM2D03.ColMatrix(15.6,-10.11));
GM2D03.Vector vecB = new GM2D03.Vector(new GM2D03.ColMatrix(15.6,-10.11));
GM2D03.Vector vecC = new GM2D03.Vector(new GM2D03.ColMatrix(-15.6,10.11));
System.out.println(/*Blank line*/);System.out.println(vecA.equals(vecA));
System.out.println(vecA.equals(vecB));System.out.println(vecA.equals(vecC));
}//end main}//end ColMatrixEquals01 class |
Once again, the code in Listing 5 is very straightforward and shouldn't require further explanation. The screen output shown in Figure 1 verifies that the library methods called by this program behaveappropriately.
Notification Switch
Would you like to follow the 'Game 2302 - mathematical applications for game development' conversation and receive update notifications?