This next lab may take longer than one hour. If you do not finish during class be sure to e-mail the code to your partner at the end of the lab. That way you both have copies of what you've accomplished so far. The goal for the lab is to learn about private variables and public mirror functions. We'll also write some convenience functions. Finally we'll add yet another routine to each of Conversation and Ruler. Seems the customer wants us to report some statistics.
Same partners, switch roles.
Start with the Conversation system as you had it last time.
If you haven't already done so, take the printing of numRulers out of MainConversation. It was just there to illustrate public variables. Keep the variable numRulers in Conversation as we'll use it later, but make it private. In fact, make all variables in both Conversation and Ruler private.
As always use javac *.java to compile. Always use java MainConversation to run.
In Ruler, add in public mirror functions for the name, title, people, and country variables.
Add in public convenience functions: Start with getIdentity(), which combines the title and name. Use it at least once in your code.
Add in two more public convenience functions: getIdentityWithCountry(), which combines title, name and country; and getIdentityWithPeople(), which combines title,name, and people. Use at least one of these with otherRuler in your sayHelloTo() routine.
The customer says we need a way to print out statistics for each ruler. There will be more statistics to come, but the customer first wants to see how many conversations each ruler has started.
Add a report() routine to Ruler and a reportRulers() routine to Conversation. The reportRulers routine will tell each Ruler to report its stats. For the moment just have the Rulers say who they are (use one of our three convenience functions to do this, you pick which one) when report() is called.
Introduce a new variable, numConversations, into Ruler. This variable should represent the number of conversations that a Ruler has started. Note that numConversations is fundamentally different from name, title and the others. We need the Conversation class to tell us what our name and title will be. We don't need Conversation to tell us anything about numConversations. The Ruler class can handle this all by itself.
As is often the case with variables you need to declare numConversations, initialize it, update it, and output it. Each of these will be done in a different place in the Ruler code. Figure out where and implement.
You are making good progress on the lab. Remember to e-mail your code to your partner (MainConversation, Conversation, and Ruler) at the end of the day even if you are not ready to submit!
At this point the output from report() should look something like: I'm President Lincoln from America and I've started 2 conversations. Unfortunately it might just as likely say: I'm Queen Cleopatra from Egypt and I've started 1 conversations.
Talk to your partner about how we might avoid that last grammatical error. Then implement the plan.
For 0 conversations, something like: I'm the lonely Queen Cleopatra and I need someone to talk to.
For 1 conversation, something like: I'm President Abraham Lincoln and I've started just one conversation.
For 2 or more conversations, something like: I'm Saint Joan of Arc and I've started 72 conversations. Of course it won't really be 72; it'll be however many conversations Joan actually started.
Please E-mail Conversation and Ruler to your partner and to me. Please include CSCI 151, date and time in your subject.