Programming Java

Tasks studies - laboratory


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

Colloquium no. 2

Task 1. (2 points).

Create a ValueNegativeException class that will throw exceptions when the number set or entered is less than zero (and should be greater than zero). Test the class.

Task 2.

Create an abstract class Animal.

B) Create interfaces with abstract methods (2 points): • IPwimming with the method: Swim(int swimspeed, int depth);IBeganie with the method: Run(int runspeed);ILatan with the method: Fly(int flyspeed, int height);IDrapedness with the method: Attack();

C) Create classes:

Implement abstract methods inherited from interfaces so that the values ​​set in them (appropriately added class fields) can only take positive values ​​(attributes: swimming and running speed, height and depth) (10 points)

D) (Note: required task - without it, the colloquium will be failed) Create a Main class with a main method as the starting point of the program. Create animal objects Jelen, Sokol, Tygrys, Pirania in the main method. For all objects, call the ShowInformacje() method. (2 points)

E) In the Main class, create static methods that allow you to enter animal data. Catch exceptions of the ValueNegativeException type and handle them in such a way that if the user enters a negative value, information about the incorrectly entered value is displayed and this method is called recursively, entering data, until it succeeds (until the user enters the correct value, greater than zero). (4 points)

F) In the main method, create an additional 10-element array that stores various animals. Go through the array using a loop and call the ShowInformation() method for each element of the array. (2 points)

Task 3. (2 points)

Create a generic class called Tuple3, implementing a three-valued tuple. Create an appropriate constructor that sets the tuple’s fields and methods that get and set these fields.