wiki:k2014/demot/demo6english
Last modified 3 years ago Last modified on 2015-02-13 11:12:21

Demot » 23.2.2015

Task 2. Date with compareTo-function

Add a static function compareTo(date1, date2) to the Date-class. CompareTo? will return -1 if the first date is before the second date, 0 if the dates are the same and 1 in the rest of the cases. Both the date1 and date2 are of type Date. TDD: Tests first for the compareTo.

Task 3*. Date with compareTo-function

Add a compareTo-method to the Date-class that takes only one parameter and will be invoked on an object of type "Date". (date1.compareTo(date2)) Then add Equals-method to the class that will define if two dates are the same. TDD: Tests first.

// Example of usage for tasks 2 and 3
Date date1 = new Date(1,2), date2 = new Date(3,3);
if ( compareTo(date1, date2) < 0 ) System.out.println(date1 + " < " + date2);
if ( date1.compareTo(date2) != 0 ) System.out.println(date1 + " != " + date2);
if ( date1.equals(date2) ) System.out.println(date1 + " == " + date2);

Task 5*. Vehicle

Create class Vehicle that stores the information of its speed and amount of passengers. Inherit from this class Ship and Airplane that both have their unique attributes compared to the vehicle. Write a small test main.

Task 6*. Arrays

Write a function indexOfTheSmallest that returns the index of the smallest item in an array full of integers. For example:

                           /*ja,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec*/
    int lengthsOfMonths[] = {31,28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

    i = indexOfTheSmallest(lengthsOfMonths); /* => i=1 */

Write a function smallest using the function indexOfTheSmallest that returns the smallest item in an integer array.

n = smallest(lengthsOfMonths);         // => n = 28 

Task 7*. Albums and songs

Draw a picture of a data structure (example can be found in luku 10). There are albums that each have songs. If your own project has this kind of data structure, picture of your project can be also used. If you will return the picture your own projects data structure, include the CRC-cards in the submission of the task 7.