Name(s) & ID(s):_________________________________________________________

Assignment P5

CS 100 � Summer 1999

Due: Thursday August 5, 1999 at the beginning of class.

Read through this entire assignment before beginning. You are strongly encouraged to work with a partner. As usual, you'll be graded on both style and correctness. WE SUGGEST YOU START THIS ASSIGNMENT EARLY.

Question 1 (40 points): (Recursion) Problems 12.20 and 12.21 in your textbook: In the language of an alien race called the Minbari, all words take the form of Blurbs. A Blurb is a Whoozit followed by one or more Whatzits. A Whoozit is the character x followed by 0 or more ys. A Whatzit is a q followed by either a z or a d, followed by a Whoozit. Design and implement a recursive program that generates random Blurbs in the Minbari language. Also, design and implement a recursive program to determine if a string is a valid Blurb as defined above. Your program should offer the user three options: 1) See a random Blurb, 2) Test a potential Blurb, 3) Quit. These should be repeatedly offered until the user chooses option number 3. Use exceptions to disallow bad input from the user. (Instructor's aside: Lest anyone think this frivolous, problems of exactly this sort are solved in virtually all modern compiler technology.) Hint: You may find the Random class and its methods useful here. See pages 130-131 of your textbook.

Question 2 (60 --110) points: (Classes, Program Design, Applets)

This is your last chance to demonstrate that you understand classes and inheritance before the final! Read through this problem carefully before beginning. This is also your opportunity to be creative. We are providing with you an outline of what we expect. You are not necessarily required to implement all of these suggestions. If you come up with something more interesting, great! Part of this problem is to get you to think creatively. All of the below are suggestions -- spend some time designing before you start implementing. Creativity counts, so does a nice, clean, logical class hierarchy, so be rigorous and careful. This problem is the bulk of this assignment, so we expect you to put a fair amount of time and thought into it. The point range is to encourage you to work hard on this problem. You'll get 60 points if you have a reasonable class hierarchy that provides adequate functionality. (Note: little credit will be given for a solution that has just a couple of classes and a couple of short methods for each class. This is a fairly large programming assignment; you should not treat the flexibility we are providing as an excuse to do minimal work.) You can get more than 60 points by adding more features and functionality -- for example, writing this problem as an applet and providing a GUI will earn more than 60 points (provided the class hierarchy is reasonable, there is sufficient functionality, and the code is correct.) Our suggestion is that you first spend time thinking about the design, then make sure that the core functionality is correct and adequate, and then, if you decide to go that far, turn the program into an applet with a GUI. It's essential that you first have a good design and correct core functionality before you try to get fancy though. It is also essential that your documentation indicate exactly what you are trying to do in the various parts of your program.

The basic idea is to design and implement a set of classes that keeps track of various (U.S.) politicians. There should be a superclass Politician, and then various subclasses, including, but not limited to: Senator, Representative, Governor, etc. What we provide below are some suggestions to give you an idea of what we're looking for. This is your opportunity to be as creative as possible. These suggestions are by no means a definitive or exhaustive list, but they should give you a few ideas to get started:

Maybe every politician has a slogan, a salary, a state they're representing, a few other things...

It might be interesting to keep track of the following:

What year was the person first elected?

How long is their term (for Senators: 6 years, for Reps: 2 years)

What year does their current term expire?

What party do they belong to?

If they're a senator, are they a jr. or sr. senator?

If they're a representative, what district do they represent?

(see next page for more suggestions)

You might start keeping an "hypocrisy meter" on each politician. For instance, pick 5 (10? 15?) political issues that politicians "care" about (or be fancy, and have each object (individual politician) have their own unique set of 5 (10? 15?) issues). Then design and implement methods to record how politicians vote on these issues and whether it agrees with their statements that they used when they were campaigning. There might then be a method that computes each politician's hypocrisy rating, and returns a 'score' based on the values you've accumulated.

You might also create some methods that keep track of how much time the politician spends fund raising and how much time they spend actually working.

Another set of methods might relate to power: which committees are the politicians on, how much seniority do they have, etc. etc. This might require developing a small committee class hierarchy. Come up with a heuristic that measures how influential the politician is.

How are Senators and Representatives different? Think carefully about which methods/fields should be in the superclass and which should be in the subclasses. Is the power structure different in the Senate than in the House, for instance? What about state governor's?

Write a driver for your classes that tests them thoroughly.

Provide the user an interface so that he or she can access information about politicians.

Provide a privileged user interface so that the privileged user can change information about politicians. You might provide a rudimentary form of password protection, here.

Provide a search facility so that users can search for a particular politician and retrieve related information. Provide a search facility so that users can search for sets of politicians who meet particular criteria (e.g. all politicians elected before a certain year, all Senators who come up for election 2002, etc.)

Provide sorting routines so that users can see lists of politicians sorted by: name, year elected, power ranking, etc. etc.

Put all this in an applet and provide a GUI to the above routines.