Programming Java

Tasks studies - laboratory


Project maintained by dawidolko Hosted on GitHub Pages — Theme by dawidolko

Lab05 - Encapsulation in Java

Task 0.

Read this before starting the exercises:
Reminder of information about encapsulation: LINK

Task 1.

Add encapsulation to all tasks from the previous outline (Lab. 03).

Task 2.

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.

Task 3.

Design a class simulating a stack structure. The class should have the following private fields:

The stack pointer indicates the top element of the stack. Implement the following methods:

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.


cmd_gcc

Task 4.

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.

Task 5.

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.

Task 6.

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.