Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
19 views3 pages

Lab 5 2

Uploaded by

tynysbekn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views3 pages

Lab 5 2

Uploaded by

tynysbekn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Lab 5

1. Task

a) Write the following method that returns the

largest element in an ArrayList:

public static <E extends Comparable<E>> E max(ArrayList<E> list)

b) Write the following method that sorts an ArrayList: public static <E extends
Comparable<E>>

void sort(ArrayList<E> list)


Write a test program that prompts the user to enter 10 integers, invokes this
method

to sort the numbers, and displays the numbers in increasing order.

c) Write the following method that shuffles an ArrayList:

public static <E> void shuffle(ArrayList<E> list)

d) Implement the following method using binary search:

public static <E extends Comparable<E>> int binarySearch(E[] list, E key)

2. Task

a) (ComplexMatrix) Use the Complex class introduced ComplexMatrix class


for performing matrix operations involving complex numbers. The
ComplexMatrix class should extend the GenericMatrix class and implement
the add, multiple, and zero methods. You need to modify GenericMatrix and
replace every occurrence of Number by Object because Complex is not a
subtype of Number. Write a test program that creates two matrices and displays
the result of addition and multiplication of the matrices by invoking the
printResult method.

Decryption of complex Matrix


https://www.algebrapracticeproblems.com/complex-matrix/

b) Use NumberFormatException class to check correct input of numbers (integer


or digit)

c) Genetare custom ComplexMatrixException class to prevent addition and


multiplication operation error
3. Task

1) Create abstract class MyCollection with all the methods below. Then,
implement

MyVector (implements MyCollection interface) class to represent a growable


array of objects.

Like an array, it contains components that can be accessed using an integer


index. Your class

will store integers.

Constructors:

MyVector() – constructs an empty vector.

MyVector(int [] a) – constructs a vector containing all integers from array a.

Methods:

add(int element)

appends the specified element to the end of this Vector.

add(int index, int element)

inserts the specified element at the specified position in this Vector. Do not
forget to throw

Exception if index is more than size.

clear()

removes all of the elements from this Vector.

contains(int o)

returns true if this vector contains the specified element.

get(int index)

returns the element at the specified position in this Vector.

indexOf(int o)

returns the index of the first occurrence of the specified element in this vector,
or -1 if this vector

does not contain the element.

insertElementAt(int element, int index)


inserts the specified integer vector at the specified index.

isEmpty()

tests if this vector has no components.

removeAt(int index)

removes the element at the specified position in this Vector.

remove(int element)

removes the first occurrence of the element in this Vector.

removeAll(int element)

removes all occurrences of element in this Vector.

reverse()

reverses the elements in the array

set(int index, int element)

replaces the element at the specified position in this Vector with the specified
element.

size()

returns the number of components in this vector.

sort()

Performs sorting of the elements in the array. Do not use sort() method of java
API.

toArray()

returns an array containing all of the elements in this Vector in the correct order.

toString() returns a string representation of this Vector

You might also like