View this PageEdit this PageUploads to this PageVersions of this PageHomeRecent ChangesSearchHelp Guide

MP2

cs598rej - Homework 2

Homework 2

Part 1. Payroll example

Exercise 1. Get the source code for the Payroll example that we did in class, downloading the file CS598rej-Payroll HW2.st You can upload the source code to your image by invoking 'open...' from the World Menu, then choose 'file list', then browse to the place where you downloaded CS598rej-Payroll HW2.st Select the file in the top right pane, then invoke the context menu (right clicking). Choose 'fileIn entire file'. You should be able to see a class category called 'CS598rej-Payroll HW2' in your class browser. Check the Employee class and the three subclasses of EmployeeTransaction to see whether they are using the proper pattern for initializing objects. In other words, whether  there is a "complete creation method" as a class method and an "instance initialization method" as an instance method. If not, fix them. For your convenience we provided some automated tests that you can download and fileIn by following the same procedure as before. The tests are at CS598rej-Grading_HW2.st You can invoke the SUnit test runner from World Menu 'open...' , then choose 'SUnit Test Runner'. Initially all the test classes in your image are selected. Deselect all and pick only GraderHW2. Run it - you should see it turns red since you have to implement some code first. After you implemented all the missing code, all but one test (testPayrollSystemWithJohn) should pass. The next exercise will guide you in making the last test pass too.

Exercise 2. Test the Payroll system. There are three test case classes already:
- SortedSequenceTestCase, which test the SortedSequence class
- EmployeeTestCase tests the Employee method changeSalaryFor:to:
- PayrollSystemTestCase tests the methods in PayrollSystem, Employee and Timecard related to posting time-cards for the Employees to earn money, checking that each one earns what's expected.

You need to add one method (call it 'testTakeHomePay') to PayrollSystemTestCase to test the methods in PayrollSystem, Employee and Paycheck related to making paychecks and checking that each employee is payed what's expected. In the 'testTakeHomePay' method create a fixture for the following case:
    "John Doe was hired May 1, 1999. His initial salary was $20 an hour. He turned in his time-card on May 5 and had
     worked 40 hours. He worked 40 hours the week of May 12, too. He received a pay-check on May 15."

Make your 'testTakeHomePay' method return the instance of the Paycheck that John Doe received. After you implemented this last feature correctly, run our grading tests again. Now, the test 'testPayrollSystemWithJohn' should pass too.

Part 2. Use of inheritance

Exercise 2.1. Suppose the following class definitions and methods:
 
Class           One
Superclass    Object
Methods 
    result1
        ^self test

    test
        ^1

Class           Three
Superclass    Two
Methods 
    result2
        ^self result1

    result3
        ^super test

    test
        ^3

Class           Two
Superclass    One
Methods 
    test
        ^2
Class           Four
Superclass    Three
Methods 
    test
        ^4

Evaluate the following expressions and explain the results:

a)

| ex1 |
ex1 := One new.
ex1 test

b)
| ex1 |
ex1 := One new.
ex1 result1

c)
| ex2 |
ex2 := Two new.
ex2 test

d)
| ex2 |
ex2 := Two new.
ex2 result1

 

 

e) Given the following assignments:

ex3 := Three new.
ex4 := Four new.

explain what happens with each of the following expresions:
  • ex3 test
  • ex4 result1
  • ex3 result2
  • ex4 result2
  • ex3 result3
  • ex4 result3


Advice


Look at the test methods to see what they are checking for (and how they check it). The test cases illustrate the reflective nature of the Smalltalk language.

Test cases also serve as a "poor man's" form of documentation. They show you a concrete example of how to create new objects and how to perform operations on them.

Deliverables


The easiest way for Part 1 is to send me the text that shows all the methods that you have added/modified. This is better than a fileOut of the entire class since that contains everything even the things that have not changed. That makes it hard for me to actually see the changs.

Use the standard notation to describe the changed methods.

For instance methods:

ClassName >> myMethodWith: param1 and: param2
"Do something here"
^ param1 + param2

For class methods:

ClassName class >>myMethodWith: param1 and: param2
"Do something here"
^ param1 + param2

Any reorganization (creating new categories, renaming existing ones) should also be stated.

For Part 2 just explain the result of each evaluation. You do not need to send me the code even if you implemented those classes to test it out.

Link to this Page

  • Machine Problems last edited on 14 May 2008 at 4:25:53 pm by c-98-212-224-168.hsd1.il.comcast.net