Tasks studies - laboratory
(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.
Create an abstract class Animal
.
String
, species: String
, age: int
.ValueNegativeException
should be thrown.WydajGlos()
and the regular (concrete) PokazInformacje()
.
The PokazInformacje()
method should display the text “Animal data:” in the console, then its name, species, age and call the WydajGlos()
method. (6 points)
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:
Deer
, Sokol
, Tiger
, Piranha
inheriting from the Animal class and implementing the appropriate interfaces (interfaces should be adapted to each animal).WydawGlos()
method and implement methods from the interfaces assigned to the class.PokazInformacje()
method by adding displaying fields added in the Jelen
, Sokol
, Tygrys
, Pirania
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)
(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.