Homework 4
This assignment involves creating both a general purpose "traditional" module as well as an object-oriented (ie, class) module in Perl
Create a class to model a video membership club account, called Rcsid::VideoClub
(where Rcsid is your RCS Id, capitalized). Each account in the
club consists of:
- An account holder's name
- An account balance due
- A purchase committment total (ie, must buy 4 more movies to satisfy your requirements)
- A list of previously purchased titles, along with the dates they were ordered.
- An account status - either "active", "fullfilled", or "closed".
Additionally, the club itself has two properties, independent of any individual account:
- Membership list
- A Featured Title for each month of the year (the movie or cd that will be sent to you automatically if you don't send back the reply card)
Class Methods
Methods available to the entire club are:
- new_account
- Takes the name of a new account holder and a membership requirement, and returns a new club account. Also increases the total membership of the club.
- members
- In scalar context, returns the number of current members of the club. In list context, returns the names of all current members of the club.
- get_account
- Takes the name of a member, and returns that member's account object. This method
should
croakif no such account holder exists. - get_title
- Takes a month (from 1 - 12), and returns the featured title for that month.
- set_title
- Takes a month (from 1 - 12), and a title name, and set's that month's feature to that title
Object Methods
Account objects have their own set of available methods:
- get_name
- Returns the name of the account holder
- get_balance
- Returns the current balance due
- purchase
- Takes a title and an amount. Adds the title to the account's purchase history (at the current date/time stamp),
and increase's the account's balance due by the purchase amount. Also reduces the account's membership requirement.
If this purchase reduces the requirement to 0, the status should be set from "active" to "fullfilled".
This method should
croakif the account's status is "closed" - make_payment
- Takes an amount, and reduces the account's balance due by that amount.
- cancel
- Marks the account as closed, and removes it from the club's membership list.
However, if the account requirements have not yet been fullfilled, or if the account still has a balance due,
this method should
croakand not update the account status or membership list. - get_status
- Returns the current status of the account, which will be either "active", "fullfilled", or "closed"
- show_history
- prints to standard output (or whatever the currently
selected filehandle is) a formatted list showing the title purchased, the date/time purchased, and the requirements left after purchasing that movie.
Traditional Module
To assist you with the final object method, you will write a generic traditional module, called
Rcsid::FormatList. This module does not define any classes or objects or methods. It has only
one purpose - to create a general use subroutine named "format_list". This subroutine takes a list
of headings, followed by an array of arrays. It returns a single string consisting of the array's
alues in a properly formatted list. By "properly formatted", we mean that the list
consists of columns. Each column is headed by the header passed in, and there is at least one blank
space between each value in each row. The starting position of the columns are consistent across
rows. This means you will have to scan the entire list to determine the column widths before building
your list. You will almost assuredly want to use the sprintf function for this task.
You may read more about it in perldoc -f sprintf.
For example, if I were to call your subroutine like so:
my @list = ( ["Paul", 29], ["Joshua", 8], ["Mary-Beth-Sue-Ann", 19], ["Amy", 100] );
my $formatted_list = format_list("Name", "Age", \@list);
Then $formatted_list would contain:
Name Age --------------------- Paul 29 Joshua 8 Mary-Beth-Sue-Ann 19 Amy 100
Remember, FormatList doesn't know anything about VideoClub or its objects.
It is a generic module that defines a subroutine that VideoClub::show_history happens
to find useful.
Module creation and Documentation & Testing
You should use the h2xs procedures we went over in class on 3/26 to create
both VideoClub and FormatList. When you submit, you will
submit the two tarballs generated by the make dist command. Don't forget
that you will have to get FormatList working and installed in order
for VideoClub to compile correctly. To create your two modules, run these
commands:
h2xs -AX -n Rcsid::FormatList
h2xs -AX -n Rcsid::VideoClub
You must write POD documentation for both modules. Each document should include a description of the module's purpose, a quick synopsis showing how it's used, a description of each mehod/subroutine, and your name as the copyright holder.
You must also create a test file for each module. I will be posting an overall test file that you can use to test your complete assignment. You should feel free to "borrow" any or all of the tests in this file for your own purposes.
Error Messages
My testing file will be checking for specific errors and associated error messages. Please
make sure you make your croak messages match the following:
- get_account passed non-existent account-holder: "No such account holder '<name>'"
- purchase on a closed account: "Closed accounts cannot make purchases
- cancel with balance due: "Account cannot be closed until remaining balance (<balance>) is paid in full"
- cancel before fullfilled: "Account cannot be closed until <requirement> more video(s) is/are purchased"
- format_list with unequal header/row values: "All data rows must have <num headers> values"
Grading Criteria
| Create a new account | 5 |
|---|---|
| Return total membership | 5 |
| Get account by name | 7.5 |
| Retrieve featured title | 5 |
| Set featured title | 5 |
| Get account holder's name, balance due, and status | 5 |
| Purchase video | 12.5 |
| Make Payment | 7.5 |
| Cancel Account | 7.5 |
Show Account history (using FormatList) |
15 |
| Documentation & Testing | 10 |
| Clean Compilation | 5 |
| Error Checking | 5 |
| Code Style | 5 |
Penalties
Late and Compilation Penalties remain the same from the first three HWs, -20 points and -50%, respectively..
Error Checking
All methods should be checked for valid input. Any time a method is called without valid input, or on
an invalid object, that method should croak with an appropriate error message.
Code Style
Your code should be easily readable to a human being. Most imporant are consistent
indentation, explanatory comments, and meaningful variable names. Please see also
perldoc perlstyle for a guide to well-styled Perl code.
Output Style
There is no output style criterion for this assignment. The only output your code should
directly generate is from the show_history method, and that method has its
own criterion.
Submission Instructions
To submit, run make dist on each of your modules to create the two tarballs. On
solaris.remote.cs.rpi.edu, run the submit program ~lallip/public/submit.pl
and follow the prompts. You should submit only the two tarballs, which will themselves contain
your modules' code, documentation, and test files.
Your submission is due at 11:59:59pm EDT Tuesday, April 8, 2008. It will be accepted up to 3:59:59pm Wednesday April 9 at a deduction of 20 points.
