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.