Programming Java

Tasks studies - laboratory


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

Colloquium I Group B

Task 1. (5 points)

Write a Java program that declares a 20-element float array and randomly selects numbers from the range 1-100. Then enter a double number n from the console. Then, from the randomly selected array, calculate the sum of numbers with odd indices and greater than n. Display the sum in the console. Test the program by calling it three times, describe the results in a comment under the code.

Task 2. (5 points)

Write a program that declares a 10-element dobule array, to which the user then enters data. Write a function that calculates the value of the sum of numbers divisible by 5 and additionally greater than the average value of the numbers entered by the user. Test the program by calling it twice, describe the results in a comment under the code.

Task 3. (6 points)

A) Create a Person class containing the following fields:

name: String; surname: float; age: int; country_of_origin: String

Note: Age should be a value between 0 and 120.

The class should have three constructor overloads, i.e.

  1. a parameterless constructor,
  2. a constructor setting the name, surname,
  3. a constructor setting the name, surname, age, country_of_origin.

Create a method called DisplayPersonData(), which will display information about the person.

B) Encapsulate the class fields by creating methods that provide fields, note that some numeric fields should always be positive.

C) Test the class by creating at least three of its objects. Objects should be created using all three constructor overloads and filled with data. If the constructor does not set a field of the class, set this data using the appropriate “set” method. Display the data of all created objects. Write the results in a comment under the code.

Task 4. (4 points)

A) Create a class Employee, inheriting from the Person class. The class also contains two fields:

job: String; staz_pracy: int;

B) Encapsulate the class fields by creating methods that provide access to the fields, note that some numeric fields should always be positive.

C) Override the DisplayPersonData() method so that it displays all the person data.

D) Test the program, as in task 3, write the results in a comment under the code.