The goal of this lab is to understand how different classes work together to make up a system and to see how objects spawned from these classes work. We'll also get more practice with routines/methods and see how to send information from one method (and one class) to another.
New partners, see Announcements.
Outside of class, please update and send me your partner evaluations. Add to your previous sheet. Consider your subject.
Create a new subdirectory called conversation.
Save MainConversation, Conversation, and Ruler all to this one directory.
Select the driver. If you haven't been the driver for a while, it's time.
Compile the system by typing javac *.java. This will compile all three classes in your new system.
Remember you only have to type that once. Then use the arrow keys to apply it again when you make changes to the code.
Always run it using java MainConversation. Do that now and note the output statements and where they're coming from in the code.
Add a public variable, numRulers, to the Conversation class as we did in lecture. Usually variables should be private, but do it this way for today.
Print this variable from the MainConversation class. Compile and run.
Add a new ruler of your choosing to the Conversation class. Compile and run.
You should see the message from Ruler coming out twice. This is because two Ruler objects have now been created.
Change the Ruler class so that the name of the Ruler is printed out along with the message. To do this, think about how the name is communicated from Conversation to Ruler.
Compile and run. Note that the changes you made to Ruler show up.
Add a name variable to Ruler.
Declare name at the top of the class because this variable will be used in multiple methods.
The name variable is of type String. A string is any sequence of letters, punctuation, digits and other characters. So your declaration should look something like private String name; Again, variables should usually be private, the one case above was an exception.
Use name to save the Ruler name passed in from Conversation.
Add an identify() method to Ruler. Have it print a nice message, not just "creating so and so", that includes the Ruler's name.
Call identify() from Conversation so that each ruler identifies itself. Remember the dot notation: lincoln.identify();
Get rid of all extraneous prints so that the only things that come out are the two Rulers identifying themselves and then the number of rulers.
Modify Conversation so that it is broken into methods as well. In particular,
Write a createRulers() method. It should contain the code that creates the rulers.
Write an identifyRulers() method that contains the code that tells each ruler to identify itself.
Call these methods from the Conversation() constructor.
Give your rulers a bit more personality in the form of a title and a country.
Do this by sending three strings from Conversation to Ruler. E.g lincoln = new Ruler("Abraham Lincoln", "President", "America" );
Receive these in Ruler. E.g. public Ruler( String nme, String ttl, String cntry).
Then save them, as you're already doing with name, and use all three when the Ruler identifies itself.
At this point Lincoln should be saying something like: Hello, I'm President Abraham Lincoln of America. And your other Ruler should be saying something similar but with its own data.
Add at least two more leaders.
Have them initialize and identify themselves.
E-mail me and your partner all four files: MainConversation.java, Conversation.java, and Ruler.java and a snippet of just the command window. As always, remember the requested subject: CSCI 151_lab time_date_subject_name(s).
Time permitting, show your running code.
Upload the three files (and the image of your command window) to Blackboard if not seen in class.
Address all questions to me or your partner (Google and YouTube OK also)