Tasks studies - laboratory
Project maintained by dawidolko Hosted on GitHub Pages — Theme by dawidolko
Lab06 - Static Class Members in Java
Task 0. Brief Introduction
Class members can be static or non-static.
Non-static members are always associated with the existence of an object (fields correspond to object elements, methods must be called on an object, and are messages to the object).
Static members (fields and methods) are shared across all objects and:
- Are declared using the
staticspecifier, - Can be used even when no objects of the class exist.
Note: Static methods must not reference non-static members of the class (as the object may not exist). However, they can refer to other static members.
Outside the class, static members can be accessed in two ways:
-
ClassName.MemberName -
If an object exists: the same way as for non-static members (note: this is misleading and not recommended).
Task 1.
Create a class Figury. Add the following code to it and test its functionality. Note that the static methods PoleKola and ObwodKola use other static methods from the Math library, which is also a class. Add additional static methods inside the class to calculate the following shapes: square, rectangle, cone, cylinder.

Task 2.
Test and describe the functionality of the following source code.

Task 3.
Create a class Complex implementing the structure of complex numbers. Add the following static methods to the class for operations on complex numbers:
- Calculating the modulus of a complex number,
- Calculating the conjugate of a complex number,
- Converting the algebraic form of a complex number to exponential form,
- Converting the exponential form of a complex number to algebraic form,
- Addition (with arguments in algebraic form),
- Addition (with arguments in exponential form),
- Subtraction (with arguments in algebraic form),
- Multiplication (with arguments in algebraic form),
- Division (with arguments in algebraic form),
- Division (with arguments in exponential form).
Also, add methods that return the value of a complex number as a string (String) in the following formats:
- Algebraic,
- Exponential,
- Trigonometric.