Defining Setters- Assigning Values to Attributes

The Procedure 

Real Lab Procedure 

  1. Define a class named Point.
  2. Inside Point class define two private instance variables: x and y, both of type int.
  3. Also define two private methods inside the Point class such as 
    • setX(int xCoord): This method takes an integer parameter xCoord and assigns its value to the x variable.
    • setY(int yCoord): This method takes an integer parameter yCoord and assigns its value to the y variable.
  4. Define another class named Driver.
  5. Define a main method within the Driver class.
  6. Inside the main method, a new instance of the Point class is created using the new keyword and assigned to a variable named P.
  7. The setX(2) method is called on the P object, passing the value 2 as the argument.
  8. The setY(3) method is called on the P object, passing the value 3 as the argument.

Class diagram Explanation 

  • On the right side of the simulation, there are two buttons [Class Diagram and Sequence Diagram].
  • First, click on the Class Diagram then the below diagrams will be shown.
  • There are two classes in the program and three parts [class name, variables, Private methods].

Sequence diagram Explanation 

  • Click on the Sequence diagram then the below diagrams will be shown. 
  • Define a main method within the Driver class. 

                 

  • Inside the main method, a new instance of the Point class is created using the new keyword and assigned to a variable named P. 

 
                 

  • The setX(2) method is called on the P object, passing the value 2 as the argument. 

 
                  
                  

  • The setY(3) method is called on the P object, passing the value 3 as the argument. 

 

Simulator Procedure

  •  There are two buttons [Class diagram and Sequence diagram] on the right side of the canvas.
  •  First, click on the Class Diagram then the below 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 is completed the result box will be shown.
  •  Click on the Reset button to redo the Simulation.