4 November 2013

A JUnit 4 Test class

package infotool;

import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;

public class InfoModelTest {

    private InfoModel instance;

    @Before
    public void setUp() {
        instance = new InfoModel();
    }

    /**
     * Test of getMessage method, of class InfoModel.
     */
    @Test
    public void testGetMessage() {
        assertEquals("welcome to mvc", instance.getMessage());
    }

    /**
     * Test of getWeather method, of class InfoModel.
     */
    @Test
    public void testGetWeather() {
        assertEquals("Sunny", instance.getWeather());
    }

    /**
     * Test of setMessage method, of class InfoModel.
     */
    @Test
    public void testSetMessage() {
        String wthString = "JUnit @Rules";
        instance.setMessage(wthString);
        assertEquals(wthString, instance.getMessage());
    }

    /**
     * Test of setWeather method, of class InfoModel.
     */
    @Test
    public void testSetWeather() {
        String wthString = "It's going to rain";
        instance.setWeather(wthString);
        assertEquals(wthString, instance.getWeather());
    }

    /**
     * Test of addModelChangeListener method, of class InfoModel.
     */
    @Test
    public void testAddModelChangeListener() {
        InfoModel instance = new InfoModel();
        InfoView view = new InfoViewTestSupport(instance);
        instance.addModelChangeListener(view);
        instance.setMessage("From testAddModelChangeListener");
        assertTrue(((InfoViewTestSupport) view).getNotification());
    }
}

1 November 2013

Java programming: extra labs

 Lesson 3

Extra Practice 3-2, Task 3

Step e. Add a method addEmployees that adds multiple employees

Lesson 4

  Extra Practice 3-2: Equals method

  1.  Add an equals method to the employee class
    1. Use employee id to test equality
      1. Make  sure that it takes into account null values and references to other classes being passed in
      2. You can use ALT+INSERT in NetBeans to insert a sample equals method
    2. Test and correct until the code succeeds
  2. Modify the equality test to use the social security number
    1. Test and correct until the code runs correctly

Lesson 5

  Extra Practice: Deck

  1. Start from the Deck lab from Java Funcamentals
  2. Replace the CardNames and CardValues arrays with enums Suit and Face
  3. Replace the decksize (52) with a number calculated from the available enums 
    1. hint: using the values() method on your enum, returns an array of all values
  4. Test and correct the code until the program runs correctly
  5. Extend the Suit enums with the corresponding unicode characters
    SPADES('\u2660'),CLUBS('\u2663'),DIAMONDS('\u2666'),HEARTS('\u2665');
  6. Extend the Face enum with numbers/names
     ACE("Ace"), TWO("2"), THREE("3"), FOUR("4"), FIVE("5"), SIX("6"),SEVEN("7"), EIGHT("8"), NINE("9"), TEN("10"), JACK("Jack"), QUEEN("Queen"), KING("King");
  7. Modify the code to display the cards using the new data
  8. Test and correct the code until the program runs correctly

Lesson 7

  Extra Practice: Couple

  1. Write a generic class Couple<S,T> that stores two values each with its own generic type
  2. Write a constructor without parameters and a constructor with two parameters
  3. Write getters and setters for each of the members
  4. Write a test, creating a Couple <Integer,String> 
    1. Try to call getters and setters respecting the given types
    2. Try to call getters and setters that do not respect the given types

Extra practice: EmployeeDAOMapImpl

  1. Write an EmployeeDAOMapImpl for practice 6-2 using a Map as internal storage. Start from a copy of the EmployeeDAOMemoryImpl 
  2. Have the factory return the  EmployeeDAOMapImpl
  3. Test and correct until the program runs well

Lesson JUnit

practice DAO

  1. Add a reset() method to the EmployeeDAO from practice 6-2 that clears the employee storage
  2. Create  a JUnit 4 testcase for the EmployeeDAO
    1. Right click on the class and select tools > create Tests
      1. The testcase is created in a dedicated test directory
      2. in which package does the testcase reside?
  3. Complete the generated testcase
    1. In the @BeforeClass method create the DAO object and store it in a static attribute
    2. In the @Before method, initialise the employee table with 3 records
      1. Hint: to make a Date object use Calendar cal = Calendar.getInstance();  
        // you can reuse the same cal object for multiple dates // set the date to januari 6th 2013
        cal.set(2013, 0, 6);
        Date d = cal.getTime();
    3. Write tests for all operations
      1. You may add a setter method to Employee for testing the update operation
  4. Right click the project and select Test (or press ALT+F6)
    1. Test until all tests succeed

Lesson 8

 Extra practice: CSV changer

Write a unit test that replaces all blanks in a file by colons. Multiple blanks should be replaced by only one colon.


30 October 2013

Flemish libraries to lend e-books

In april 2014 Flemish libraries will start a pilot project to extend their offer with e-books. The initial pilot will run for a year and the catalog wil contain 300 titles.
You will be able to read them for free in the library.  For reading anywhere readers will be charged using the 345-model: maximum 3 ebooks fro maximum 4 weeks will cost €5.
The e-books will be readable using an app for Android and Apple. They will not be readable using an e-reader device, like Amazon Kindle, unless it can run Android apps. This limitation was needed to enforce the 345 lending model.
Here's a presentation for libraries that want to participate in the pilot project. Below is an infograph on ebooks ales evolution from 2011 => 2012, taken from the presentation:



25 September 2013

Java fundamentals: extra labs

Lesson 6

Extra practice: Extend Customer Info

  1. Modify lab 6.1 to ask the user to enter the attributes of the customer
  2. Use java.util.Scanner to read the attributes
    1. Take care: after reading an int, you also need to read the return (newline) to advance to the next line of input

Lesson 7

Practice 7.1:

Modify the exercise to:
  1.     Use a java.util.Scanner to read the time of the day from the user input.
  2.     Allow the user to use the format hh:mm:

Extra practice: Seasons

  1.  Create a class Meteo with a method
  2.     public String getSeason(String month) 
  3.  Implement the method and let it return the meteorological season for the month 
    1. (e.g. for december to february return winter)
  4. Create a class MeteoTest
  5. Write a main method that
    1. Creates a Meteo object
    2. Asks the user for the name of a month
    3. Uses the Meteo object to get the corresponding season
    4. Prints out the season
  6. Run the test program and correct errors until it succeeds
  7. Modify the program to make it work no matter which case the user uses when entering the month.
  8. Run the test program and correct errors until it succeeds

Lesson 8

Extra practice: Deck

  1. Create a class Deck  
  2. Initialise a cardNames array with the value of all cards (ace, two, three..., jack, queen, king)
  3. Initilise a cardSuites array with the suites of all cards (hearts, spades, clubs, diamonds)
  4. Create a method called printSize, which
    1. prints the number of cardValues
    2. prints the number of cardSuites
    3. prints the number of cards
  5.  Create a class DeckTest
  6. Write a main method that
    1. Creates a Deck object
    2. Calls printSize on it
    3. Run the test program and correct errors until it succeeds
  7. Write a method drawCard, which prints the name of a random card (e.g. jack of spades)
    1. Hint: use Math.random()
  8. Draw two cards from the main method
  9. Run the test program and correct errors until it succeeds

Lesson 9

Extra practice: Dice

  1.  Create a class DiceStat with a method
  2.     public void printStat () 
  3. The method should roll 2 dice 10.000 times (Hint: use Math.random()
  4. Print the number of times each number was rolled
  5.  Create a class DiceTest
  6. Write a main method that
    1. Creates a DiceStat object
    2. Calls printStat
  7. Run the test program and correct errors until it succeeds
  8. For each result, express as a percentage, how often it is thrown
  9.  Run the test program and correct errors until it succeeds

Extra practice: Factorials

A factorial (n!) is the product of all numbers less than or equal to n. Example:

3!= 3*2*1

Create an application, called factor that will print the factorial of the number given as an argument to the application:

$ java FactorTest 3
3! = 6

Lesson10

Extra practice: Quiz

  1.  Create a class Quiz with keywords and definitions.You can find the keywords and definitions here.
  2. Create a method with signature
  3.     public boolean askQuestion()
    1. The method asks the user to give the keyword that corresponds to a randomly chosen definition
    2. The method compares the answer with the  keyword
    3. The method informs the user about the correctness of the result.
    4. If the answer was wrong, it shows the correct keyword
    5. The method returns if the respons is correct
  4. Create a class QuizTest
  5. Write a main method that
    1. Creates a Quiz object
    2. Calls askQuestion
  6. Run the test program and correct errors until it succeeds
  7. Add a method with this signature
  8.       public int askQuestions(int number) 
    1. The method asks multiple questions
    2. The method returns the number of correct answers
  9. Call the method from the main class
  10. Run the test program and correct errors until it succeeds
  11. Add a method with this signature
    1.  public boolean certify (int numberOfQuestions, int passPercentage)
    2. The method prints out your score percentage.
    3. The method prints out whether you passed the certification or not.
    4. The method returns a boolean with the pass result.
  12. Call the certify method from the main class
  13. Run the test program and correct errors until it succeeds

Extra practice: Hypothenuse

The hypotenuse is the longest side in a right angled triangle. Pythagore's theorem states that the length of the hyothenuse (h) relates to the two other sides (x and y)  as:

Write a program, using that calculates the hypothenus, using java's Math class:

$ java HypothenuseTest 2 3
Hypothenuse = 3.6

Lesson 11

Extra practice: Unique object ID's

  1.  Modify the Rectangle class to assign a unique ID to each object that is created.
    1. Start the ID's at 1 and increment for each new object
    2. Print the rectangle ID in the creation message from the constructor
  2.  Run the test program and correct errors until it succeeds

Extra practice: Deck

  1.  Add a Card class to the Deck project
    1. Add a suit and value attribute and methods to retrieve them
    2. Add a Constructor 
    3. Add a method that returns the card name (e.g. queen of hearts) with signature
         public String toString(); 
  2. Add a constructor to the Deck class that generates a Deck of 52 cards.
  3. Modify the drawCard method to return a Card
  4. After calling drawCard, print out the card name from the main method.

Extra practice: Dice constructor

  1. Add a constructor to the DiceStat class that accepts the number of dies, the number of sides each dice has and the number of throws.
  2. Make the Deck class generic to work with these variables.
  3. Run the test program and correct errors until it succeeds

Lesson 12

Extra practice: Rectangle class hierarchy

  1. Make a class Square, that is a subclass of the Rectangle class. 
    1. Add a Constructor that takes the side as an aargument
  2. Draw a square from the RetcangleTest main method
  3. Run the test program and correct errors until it succeeds
  4. Make rectangle a subclass of Shape. Make a class Shape with an abstract draw method.
    1. In Rectangle you can also use Refactor => extract interface
  5. Make a Triangle class that extends Shape (In the interface, you can press ALT+ENTER to generate a class that implements the interface)
    1. This class is a right angled triangle, with equal width and height. Example:
    2. *
      **
      ***
      ****
    3. Implement the necessary methods
  6. Draw a triangle from the RetcangleTest main method
  7. Run the test program and correct errors until it succeeds
  8.  Make a Canvas class, with a method with signature
  9. public void draw (List shapes)
    1. In the draw method  loop over the list
    2. Assign the objects from the list to a Shape variable
    3. Draw each Shape
  10. In the main method of TestRectangle, create a Canvas
  11. Add a number of rectangles, Squares and triangles to an Arraylist.
  12. Call the draw method on the canvas, and pass the arraylist to it.
  13. Run the test program and correct errors until it succeeds
  14. Make a Parallellogram class that extends Shape (you can make a copy of the Rectangle class and name it Parallellogram to start)
    1. This class draws a parallellogram with a slope that indents one character:
    2. ****
       ****
        ****
    3.  Implement the necessary methods
  15. In the main method of TestRectangle, add some paralellograms to the ArrayList
  16. Run the test program and correct errors until it succeeds

22 September 2013

Firefox on windows 64 bit : use the 32 bit plugins

When installing the java plugin on windows 64 bit (I have windows 7), which Java plugin do I need?
64 bit seems the logical choice.
Here's what Oracle, steward of Java says at this time:

Java for 64-bit browsers
Users should download 64-bit Java software, if they are running 64-bit browsers.
Allright, now do I have a 64 bit firefox, the page tells me how to check

Verify if you are using 32-bit or 64-bit browser


Firefox
To determine whether you are running on a 64-bit version of Firefox, use either of these methods.
  • Check the About Firefox panel
  • Type in the browser address about:support
If you are running 64-bit Firefox, it may be indicated as 64-bit (e.g., Win64); otherwise it is a 32-bit version of Firefox.  
 What can I find on this page?


 User Agent     Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0

There's a number 64 in there, but take care: this indicates that windows is 64 bit. To really know more about your firefox you need to follow the about:buildconfig link. oracle should recommend to type that one directly. Look at the target entry:

target i686-pc-mingw32

This is a 32 bit build after all. As a matter of fact, Firefox does currrently not provides a production quality 64 bit build for Windows. On Windows, Firefox currently is a 32 bit application, hence you always take the 32 bit plugins.

2 September 2013

Excel 2010 Advanced Filtering



The official excel (advanced) filtering doc is a step by step guide for some common cases, but does not explain well how it actually works.
The common case is not what i commonly need, so I lose time and patience looking this up.
So I'd better keep a good excel advanced filtering resource around in case I ever need this again.

Remark: every time you change your filter (or sorting) criteria, you have to point the advanced filter to the filtering criteria again. The only way to avoid this is to add a macro to your spreadsheet.

Adidias NEO window dressing

My colleague Eytan pointed me to this Video on Adidas window shopping.
Adidas mounted a giant touch screen in front of the shopping window,
on which you can by goods using a tablet interface.
Looks great!