Programming Java

Tasks studies - laboratory


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

Colloquium 3

Task 1.

Write a program that displays numbers from 10-0, excluding numbers {8,6,3,1}. To perform the task of excluding, use the continue statement;

Task 2.

Implement an algorithm that calculates the value of the Fibonacci sequence (recursion)

Task 3.

Create a class that stores an array of 10 integers (the array is a field of the class), which is encapsulated. a) Create a method that allows the user to enter numbers. b) Create a method that displays the contents of the array on the console. c) Create a method that returns the average value of the array elements. d) Create an object of the designed class and test the actions of the methods in the main method.

Task 4.

Create a Person class containing fields specifying name, surname, age, height and weight. Use field encapsulation. Create methods to get and set field values. Create at least two constructors of the Person class. Create a method to display the person’s data. Create an object of the Person class and display the person’s data.

Task 5.

Create an Employee class that inherits from the Person class. Add two fields to it: profession and earnings. Override the method displaying employee data, which was inherited from the Person class, so that it also displays profession and earnings. Create an object of the Employee class and display the employee’s data.

Task 6.

Write a program that displays numbers from the range 200-0, excluding odd numbers.

Task 7.

Create a class that stores an array of real numbers. The array has a size set by the constructor. Create methods that allow you to: - fill in array cells,

Task 8.

Create an abstract class Animal with fields: name, weight, age and methods Eat, Breathe, ShowData. Create a class constructor and its overload. The Animal class is inherited by the concrete classes Tygrys, Orzeł, Duck, Shark. Classes also inherit from interfaces. The following interfaces are available: IBieganie, ILatanie, IPswiwanie, IPolowanie. Choose the appropriate interfaces for the classes describing animals and add the appropriate methods to the interfaces. Create several animal objects and place them in an ArrayList. Iterate through the collection to display data describing all the animals.

Task 9.

Create a class that throws an exception when trying to divide by 0. The class should inherit from java.lang.Exception. Then create a class that tests whether division by zero exceptions are thrown using the previously created class and caught.