CS494 Skills Demo, Spring 2005

There are four sections below, A, B, C and D. In each section there are a set of instructions or tasks. Do them and show the TA that you've completed them, or if a check-off is indicated, stop at that point and demo what you've done to the TA.


A. Creating a New Project and Using JUnit:

  1. Create a new Java project, and do what it takes to make sure it that it will work with JUnit.
  2. If there is not a source-code folder named src in the project, then right-click on the project, chose New, and then Source Folder.
  3. Create a new class called Pair, and add a constructor with this signature:
    public Pair(Object x, Object y)
    that assigns x to a variable named item1 and y to a variable named item2.
  4. Then use Eclipse QuickFix to make item1 and item2 fields of class Pair.
  5. Check-off: Show the TA what you've done, and explain what you did in step 4.
  6. Eclipse makes it easy to create a new JUnit test-case class for Pair. Do this.
  7. Soon we'll create a swap() function in Pair, but create the test-case first. In the test-case class, create testSwap() as follows. (You can cut-and-paste this code.)
    public void testSwap() { 
       Pair p1 = new Pair("hello", "there");
       p1.swap();
       assertEquals( p1.item1, "there");
       assertEquals( p1.item2, "hello");
    }
  8. Use Eclipse QuickFix to add the swap() method and to fix any other problems in the code.
  9. Check-off: Show the TA what you've done, and explain what you did in step 8.
  10. Before modifying swap(), run the JUnit test-case and show that the test failed.
  11. Code the swap() function to make item1 refer to the string that item2 initially referred to, and item 2 refer to what item1 initally referred to. (Use a temp variable of type Object.)
  12. Rerun the test and show that it works.
  13. Check-off: Show the TA what you've done, and explain what you did in step 4.


B. Working with Large Projects:

We'll use a Monopoly game written in Java (complete with JUnit testcases) developed at North Carolina State University.

Get a copy of this project's source files (in Zip format) and create a new Java project, then import these files.

You should see the java files in packages under src but some of them will have red error-indicators. To fix that, you'll need to add JUnit to your project build-path after you import the files. (If you don't know how to do this for this project, the TA will do it for you.)

Do two of the following 3 commands. Show the TA how you do these.

  1. Use an Eclipse command to find out which classes implement the edu.ncsu.monopoly.MonopolyGUI interface.
    Also, use an Eclipse command to find out which classes are subclasses of the Card class.
  2. Open the Call Hierarchy view for Java. Then go to the Player class.
    Find the canBuyHouse() method in the Outline view.
    Use an Eclipse command to find out what other methods in the Monopoly application actually call the canBuyHouse() method.
  3. Of the two packages in this application, which has the larger value for the package Abstraction metric?


C. Reverse Engineering:

  1. Create a class diagram for the gui package and show it to the TA. Your class diagram should show both inheritance and association relationships. Show the diagram in full-screen mode. (Don't worry if you run into any restrictions due to our using an evaluation license.)
  2. Find the method GameMaster.btnPurchasePropertyClicked() and create a sequence diagram starting with a call to that function. Show this to your TA.


D. Refactoring:

Show the TA you can do both of the following things:

  1. In class GameMaster, find the method completeTrade(). In that code, you'll see that deal.getAmount() is called twice.
    Use an Eclipse command to assign this expression to a variable and replace the repeated code in the method.
    Also, run the JUnit test on this class to show that all 8 tests still run without error.
  2. In class Player, find the field named position. Start the process in Eclipse of changing the name of this field to posn -- but don't actually complete the changes. Instead, show the TA what Eclipse would change if you actually confirmed that you really wanted to make these changes.