Sunteți pe pagina 1din 2

Java Lab Assignment-03 Class m tech

1. Develop and implement a class LinearArray that represents a single-dimensional array. Attributes array int[] An integer array Methods LinearArray() Configures a new LinearArray object with length 10 and the elements initialized to 0 LinearArray(int r) Configures a new LinearArray object with no. of elements r and all initialized to 0 LinearArray(int r, int k) Configures a new LinearArray object with no. of elements r and all initialized to k LinearArray(int r, int[] a) Configures a new LinearArray object with no. of elements r and whose elements are initialized to 1D array a void displayArray() Displays the elements of the associated LinearArray object void displayReverse() Displays the elements of the associated LinearArray object, in reverse order int getlength() Returns the length of the associated LinearArray int findMinimum() Returns the minimum element of the associated LinearArray object int findMaximum() Returns the maximum element of the associated LinearArray object int linearSearch(int k) Returns the index position of the element k in the associated LinearArray object (if the element is present in the array), otherwise -1.(Method: Linear Search) int binarySearch(int k) Returns the index position of the element k in the associated LinearArray object (if the element is present in the array), otherwise -1. (Method: Binary Search) void incrementBy(int k) Increases all the elements of the associated LinearArray object by value k void decrementBy(int k) Decreases all the elements of the associated LinearArray object by value k void sortArray() Sort the elements in increasing order of the associated LinearArray object Object clone() Returns a new LinearArray that is a duplicate of this LinearArray object String toString() Returns a textual representation of the associated LinearArray 2. Develop and implement a class Matrix that represents a two-dimensional array. Attributes data int[][] An integer 2D array r int No. of rows c int No. of columns Methods Matrix() Configures a new Matrix object of size 10X10

with all elements initialized to zero Matrix(int m, int n) Configures a new Matrix object with size m X n and all elements initialized to 0 Matrix(int m, int n, int v) Configures a new Matrix object with size m X n and all elements initialized to v Matrix(int m, int n, int[][] a) Configures a new Matrix object with size m X n and elements initialized using 2 D array parameter a Matrix add(Matrix a) Returns the matrix addition of this matrix and matrix a. Matrix multiply(Matrix a) Returns the matrix product of this matrix and matrix a. int getRows() Returns the number of rows of the associated Matrix object. int getColumns() Returns the number of columns of the associated Matrix object. Object clone() Returns a new matrix that is a duplicate of this matrix int findMaximum() Returns the maximum element of the associated Matrix object int findMinimum() Returns the minimum element of the associated Matrix object void fill( int t) Sets all elements of the associated Matrix object to t. static Matrix identityMatrix(int m) Returns a new matrix of order m. All elements are initialized to 0 except the diagonal elements which are initialized to 1 int get(int i, int j) Returns the value of the element in the ith row and jth column of the associated Matrix object String toString() Returns a textual representation of the associated Matrix object 3. Design a class to represent a Rectangle. Include the following i. Data members: Length, width ii. Member functions a. Parameterized constructor that initializes the data members b. area() function that calculates the area of the rectangle. 4. Design a class to represent a Student. . Include the following i. Data members: Name, age, address, marks ii. Member functions a. Parameterized constructor that initializes the data members b. show() function that displays the student information 5. Develop an application, which accepts the basic pay of the employee and calculates the total salary. i. Data members: Basic_pay ii. Methods: To calculate the total salary Conditions: HRA=10% of basic DA=15% of basic Deductions House loan=1500 Car loan= 800 Personal Loan= 500

S-ar putea să vă placă și