Extend the functionality

The Procedure

Real Lab Procedure

  • First, click on the class diagram then the below diagrams will be shown. 
  • There are two classes in the program, and it has three parts [class name, variables, function]. 

Fig 1 

Fig 2 

  • Fig 1 shows the class diagram of class Point. 
  • Fig 2 shows the class diagram of class Driver.  
  • Then click on the sequence diagram which will show how the program that on the left side is executed. 

             Sequence diagram 

Following steps are explaining sequence diagram. 

  • The code defines a class called Point, which represents a point in 2D space with x and y coordinates. The class has two private instance variables: x and y. 
  • The Point class has two constructors. The default constructor Point() initializes the x and y coordinates to 0. The parameterized constructor Point(int xInit, int yInit) allows you to initialize the x and y coordinates with specific values. 
  • The class has private getter and setter methods for both x and y coordinates. This follows the principles of encapsulation, keeping the instance variables private and providing controlled access through methods. 
  • The class also has a private method print() which prints the coordinates in the format "(x,y)". 
  • The isOrigin() method is defined, which checks if the point is at the origin (coordinates (0,0)). 
  • Next, a class called Point3D is defined, which extends the Point class. This new class represents points in 3D space, with additional z coordinate. 
  • The Point3D class has a protected instance variable z representing the third coordinate. 
  • Public getter and setter methods for the z coordinate are provided: setZ(int zCoord) and getZ(). 
  • The isOrigin() method is overridden in the Point3D class to take into account the third coordinate z. It calls the isOrigin() method from the superclass (Point) using super.isOrigin(), and also checks if z is 0. 
  • Finally, there's a Driver class with a main method. However, there's a small issue in the code. The main method signature should be public static void main(String[] args) instead of public static void main(String[]). 
  • Inside the main method, an instance of the Point class p is created using the default constructor. An instance of the Point3D class p3 is also created. 
  • The isOrigin() method is called on the p object, but the result is not stored or printed, so it doesn't have any visible effect. 
  • The setZ(0) method is called on the p3 object to set its z coordinate to 0. 
  • The isOrigin() method is then called on the p3 object. This method considers both the x, y coordinates from the superclass and the z coordinate specific to the Point3D class to determine if the point is at the origin. However, the result is not stored or printed, so it also doesn't have any visible effect. 

 

Simulator Procedure 

  • There are two buttons [Class Diagram and Sequence Diagram] on the right side of the simulation.
  • First, click on the Class Diagram then the class diagrams will be shown.
  • Then click on the Sequence Diagram, it will display two buttons – Previous and Next.
  • The Next button shows the next sequence, and the Previous button shows the previous sequence.
  • After all the sequence diagrams the result box will be shown.
  • Click on the Reset button to redo the simulation.