CS 201 - Computer Science I - Spring 2004
Project 2
Loyola College >
Department of Computer Science >
CS 201 >
Projects >
Project 2
Due
Monday, March 22th at 11:59pm.
Projects will be penalized 20% for each day after the due date.
Projects will not be accepted more than four days late.
Objectives
- to use named constants
- to use conditional statements
- to test classes
Introduction
Imagine Tivo is developing its next generation product which will use profiles of individual family members to determine which shows to record. We will develop a class to represent a viewer profile. One instance of this class will contain all the information Tivo associates with a particular person. There will be fields for the viewer's name, age, gender, show preference, maximum number of hours that Tivo can record for that person, and the number of hours that have been recorded. (We will assume that equal length programs take up the same amount of space on the hard drive.)
This class will also have several methods that will record and erase shows based on the profile, and other methods that will access the information stored in the profile.
A sample profile might look like:
- Name: Dad
- Age: 48
- Gender: male
- Show Preference: sports
- Maximum hours: 10
- Hours used: 3 (3 episodes of Sports Center)
Since we are developing a "Tivo2" prototype, there will be some limitations to our software. First, we will not keep track of the individual shows recorded, only their hours. Second, we will deal only with a subset of genres: comedy, reality, sci fi, soaps, and sports. Third, we will record shows based on the viewer's preference and demographic information only. We will use the following demographic rules:
- People under 30 watch comedy
- People between the age of 15 and 40 watch reality TV
- Sci fi is watched by men ages 12 to 25
- Soaps are watched by women over the age of 15
- Sports are watched by men over the age of 18
In our system each show will be identified by a unique 12 digit number. The first number will indicate the rating, the second the genre, numbers 3 through 6 will be the number of minutes the show runs, and the final six numbers indicate the unique show id.
Both Rating and Genres will have associated numeric values, which are listed in the following tables. Shows can run for a maximum of 9999 minutes, and for our purposes the six digit unique id can be generated randomly.
Rating Table
|
Genre Table
| Comedy | 0 |
| Reality | 1 |
| Sci Fi | 2 |
| Soaps | 3 |
| Sports | 4 |
|
Using the above information a show number of 320060388474 would indicate that show 388474 is a Science Fiction show rated PG-13 which runs for 60 minutes.
Ratings will be used to determine if a family member can record a particular show. Shows rated NR and G can be recorded by members of all ages. Shows with a rating of PG-13 can only be recorded by those 13 and older, and shows with a rating of R can only be recorded by those 17 years and older.
Assignment
Write a class called Tivo2. This class should have at least
the following attributes:
- fields as described above
- a constructor to create a new profile with the signature
Tivo2(String name, int age, char gender, int favoriteGenre) where gender will be the character 'F' for female and 'M' for male, and favoriteGenre will be an integer from the Genre Table above. The default number of hours recorded for each profile is 10 hours
- another constructor
Tivo2(String name, int age, char gender, int favoriteGenre, int maxHours)
will create a profile that can record up to the number of hours specified in maxHours
- a method isUnder13 that returns true if the family member is under 13 years old and false otherwise
- a method isUnder17 that returns true if the family member is under 17 years old and false otherwise
- a method isFemale that returns true if the family member is female and false otherwise
- a method getFavoriteGenre that returns the viewer's favorite genre
- a method setFavoriteGenre that changes the viewer's favorite genre to the one specified
- a method celebrateBirthday that increments the viewer's age by one year
- a method recordShow that takes a show number and records the show if and only if the viewer has sufficient space to store the show, and if the user has permission to view the show (based on its rating)
- a method autoRecordShow that takes a show number and records the show if the genre is suited to the viewer based on preferences or demographics, the user has sufficient space to store the show, and if the user has permission to view the show based on its rating
- a method clearShow that takes a show number, assumes it has been recorded, deletes the show, and frees the corresponding a segment of disk space
- named constants as appropriate
- other private methods to reduce redundancy in the code. Any computation that has to be performed for multiple methods should be written in its own method
You should also write a test driver to test your methods thoroughly.
Hint: Show Ids must be of type long because an int cannot hold such a large number. Also when creating show ids for testing you will not be able to create an id with the following statement:
long id = 999999999999;
because java will first create an int and then turn it into a long. Instead you will need to use something like the following technique:
long id = (long)rgmin * 1000000 + uniqShowID;
where rgmin is the rating, genre, and running time and uniqShowID is the randomly assigned number for the show.
Grading
- 60% Execution. Partial credit will be granted depending on how
much progress you made towards the correct result.
- 20% Design. The design score is based on how easy it is to
follow the logic of your code, how well you avoided repetitive code,
and how easy it would be to change your code if certain specifications
changed.
- 10% Testing. The testing score is based on how thoroughly you
test your code. Even if your Tivo2 class
functions perfectly, you will get a 0 for testing if you do not
write a test driver.
- 10% Style. Style includes comments, indentation, and choice of
variable and method names.
- Substantial progress must be made towards correct execution to
earn the points for design and style.
Submissions
Submit the source code (.java file) for your Tivo2 class
and your test driver.