Java SE 8 API documentation

Last modification: 10/10/2016

  1. Write a math.Matrix class which consists of matrix operations. The operations are as follow.

    1. A plus() class method, which takes two two-dimensional array of integers as arguments and adds them together. The method returns the result as a third two-dimensional array.

      The sum of the \(A\), \(B\) \(m \times n\) matrices is a \(C\) \(m \times n\) matrix for which \(C_{ij} = A_{ij} + B_{ij}\).

    2. Intermediate level. A multiply() class method, which similarly to plus() also takes two two-dimensional array of integers as arguments and multiplies them together. The method returns the result as a third two-dimensional array.

      The product of the \(A\) \(m \times n\) and \(B\) \(n \times k\) matrices is a \(C\) \(m \times k\) matrix for which \(C_{ij} = \sum_{k = 0}^n A_{ik} \times B_{jk}\).

  2. Write a program that checks whether or not its argument is a palindrome.

    A word or phrase is a palindrome which reads the same backwards or forwards.

    1. Suppose that the argument consists of one word. For instance:

      $ java Palindrome noon
      true
      
      $ java Palindrome radar
      true
      
      $ java Palindrome tree
      false
    2. Extra exercise. Enhance your program so that it can handle phrases of several words. For instance:

      $ java Palindrome "race car"
      true
  3. Write a program that reads as much lines from the standard input as as it can. Then it writes the lines to the standard output in reverse order. Use a java.util.LinkedList<A> object in order to store the lines.

    Note:

  4. Write a class IntList in a util package, which represents a list of integers. Add the following field and constructors.

    1. A private array of integers.

    2. A public no-argument constructor.

    3. A public copy constructor that takes an other IntList object, which is used to initialize the array of integers.

    The IntList is exactly as large as the number of integers. The effect of the add() is that the IntList grows by one, while the effect of remove() is that the IntList shrinks by one. In order to create a new larger or smaller array use the java.utils.Arrays.copyOf() method.

    The methods of the IntList are as follows:

    1. size(), which returns the number of integers.

    2. get(), which returns the first integer.

    3. get(), which returns the integer with the given index (overloaded version).

    4. add(), which appends an integer to the end of the list.

    5. add(), which appends an integer to the given index.

    6. toString(), which converts the list to a string. The elements should be separated by a comma in the string.

    Extra exercise. Implement the following methods as well.

    1. fromString(), which is a static method that converts its string parameter into an IntList. The numbers are separated by a whitespace in the string. Return a null reference if the conversion fails.

    2. set(), which overwrites an element with an other at the given index.

    3. remove(), which removes the last element and returns it.

    4. remove(), which removes the element at the given index and returns it.

    5. indexOf(), which returns the index of the first occurence of its parameter or \(-1\) if the parameter is not in the list.

    6. concat(), which appends an IntList to the end of the list.