Tasks studies - laboratory
Read this before starting the exercises:
Reminder of information about encapsulation: LINK
Add encapsulation to all tasks from the previous outline (Lab. 03)
.
Design and create a class describing a book in a bookstore. Books have the following attributes: title
, author
, number of pages
, year of publication
, price
. Apply encapsulation to the fields in the class, ensuring that only the price of the book can change over time, while the other attributes are immutable (read-only). Create example objects and demonstrate how to access object fields through methods.
Design a class simulating a stack structure. The class should have the following private fields:
n
-element array of integers representing the stackThe stack pointer indicates the top element of the stack. Implement the following methods:
push
: places an element on top of the stackpop
: removes the top element from the stack.Ensure that it is impossible to push a value onto the stack if it is full, and impossible to pop a value from an empty stack. Note that the push
and pop
instructions behave like get
and set
.
Create a constructor that accepts the stack size as an argument. Within the constructor, initialize the n
-element array representing the stack. Remember that the push
and pop
instructions modify the stack pointer accordingly.
Define a class describing a date. Consider the choice of internal representation for dates. Implement methods to read the current date and shift it by one week forward and backward. Ensure appropriate access modifiers are applied to the class fields.
Define a class Pracownik
(similar to the Osoba
class from the lecture, adding a text field for the employee’s job position). Then define a class Firma
to store an array of all employees (you can assume the number of employees does not exceed 100). Implement methods for adding new employees to the company and displaying the current list of employees. Consider how to distribute responsibilities between the two classes for this task.
Define a class Liczba
that stores the digits of a decimal number in an array. Implement the following operations:
If, during multiplication, the array is too small, the multiplication procedure should copy its contents to a larger array. Finally, define a method silnia
to calculate the factorial of a number given as an integer parameter.