Question
Create a program in JAVA with the following components and functions: 1. Create an abstract class (or interface) Field_ with parameters: int m and n
Create a program in JAVA with the following components and functions:
1. Create an abstract class (or interface) Field_ with
parameters: int m and n
abstract method print();
2. Create a class Array_ that inherits from Field_ and has
A parameter private array int[], that is defined as an array of 10 elements, in the constructor.
A parameterless constructor that performs the aforementioned definition
Method print() with which the elements of the array are printed (tabulated)
Method int getElement(int i) which returns the element at position i.
Method setElement(i, value), with which the element a[i] obtains the value value
3. Create a class Matrix_ that inherits from Field_ and has
A parameter private matrix int [][], that is defined as a matrix [10][10], in the constructor.
A parameterless constructor that performs the aforementioned definition
Method print() with which the elements of the matrix are printed (as a table)
Method int getElement(int i, int j) which returns the element at position [i][j].
Method setElement(i, j, value), with which the element [i][j] obtains the value value
In the main class, create an array of 5 objects from the class/interface Field_.
Use a for cycle to simulate input of objects in the array in the following way.
In the i-th step
The client first inputs a number a type indicator which will create (1 = array, 2 = matrix)
If an array is input,
In the array of Field_ objects, create an Array_ object on the i-th position.
The client inputs the number of elements m (a parameter of Field_) and inputs the elements in that array (through the keyboard).
If a matrix is input,
In the array of Field_ objects, create a Matrix object on the i-th position.
The client inputs the number of rows m and columns n (parameters of Field_) and inputs the elements in that array (through the keyboard).
After you input the elements in the Field_ array, calculate the average of the elements input in ALL arrays.
Finally, output the elements of the Field_ class/interface objects.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started