Use class abstraction and encapsulation concepts to re-draw the UML class diagram of Square class that you drew in Lab 02. Discuss: Do you think the data field (side) should be declared private (hidden)? Why? If the data field is declared private (hidden), how the data field can be accessed from outside the class (for example, from the Test class)? The new UML class diagram should include the getter and setter methods which deal with the data field side. Create a new Java Application project called lab_03. Copy the source files of the classes java and TestSquare.java that you created in Lab 01 and paste both source files in the default package. (you may need to fix any problems related to package declaration) Open Square and TestSquare classes using NetBeans editor. Use class abstraction and encapsulation concepts to modify the implementation of Square class, so the new class implementation would satisfy the class abstraction and encapsulation concepts. Add any required getter and setter methods to the class Square. Fix any compiling errors in the TestSquare class as a result of modifying the class Square. Run the Test TestSquare
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
- Use class abstraction and encapsulation concepts to re-draw the UML class diagram of Square class that you drew in Lab 02.
Discuss:
Do you think the data field (side) should be declared private (hidden)? Why?
If the data field is declared private (hidden), how the data field can be accessed from outside the class (for example, from the Test class)?
The new UML class diagram should include the getter and setter methods which deal with the data field side.
- Create a new Java Application project called lab_03.
- Copy the source files of the classes java and TestSquare.java that you created in Lab 01 and paste both source files in the default package. (you may need to fix any problems related to package declaration)
- Open Square and TestSquare classes using NetBeans editor.
- Use class abstraction and encapsulation concepts to modify the implementation of Square class, so the new class implementation would satisfy the class abstraction and encapsulation concepts.
- Add any required getter and setter methods to the class Square.
- Fix any compiling errors in the TestSquare class as a result of modifying the class Square.
- Run the Test TestSquare
Step by step
Solved in 2 steps with 4 images