Tasks studies - laboratory
(5 points)
Write a Java program that declares a 20-element array of float numbers and randomly selects numbers from the range 1-100. Then enter a double number n from the console. Then calculate the sum of odd numbers and numbers greater than n from the randomly selected array. Display the sum in the console. Test the program by calling it three times, describe the results in a comment under the code.
(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 3 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.
(6pts)
A) Create a Product class containing the following fields:
name: String;
price: float;
barcode: int;
country_of_origin:String
Note: Barcode should be a value between 10000000 and 99999999.
The class should have three constructor overloads, i.e.
Create a method called DisplayProductData(), which will display information about the product.
B) Encapsulate the class fields by creating methods that provide fields, note that some numeric fields should always be positive. (4 points)
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.
(4 points)
A) Create a class Cart, inheriting from the product class. The class also contains two fields:
capacity: float;
material:String; // describes what the basket is made of.
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 DisplayProductData() method so that it displays all product data.
D) Test the program, as in task 3, write the results in a comment below the code.