//******************************************************************** // Ruler.java Author: CSCI151 // // An individual ruler who can talk to others //******************************************************************** public class Ruler { private String name, title, country, people, greeting; private int numConversations; private Ruler lastSpokenTo; // A series of mirror functions follow public String getName() { return name; } public String getTitle() { return title; } public String getCountry() { return country; } public String getPeople() { return people; } // A series of convenience functions follow public String getIdentity() { return title+ " " + name ; } public String getIdentityWithCountry() { return name+ " " + title + " of " + country; } public String getIdentityWithPeople() { return name+ " " + title + " of the wonderful " + people; } public Ruler( String nme, String ttl, String ctry, String ppl, String grt ) // Remember my info { numConversations = 0; name = nme; title = ttl; country = ctry; people = ppl; greeting = grt; } public void identify() // Identify myself { System.out.println(greeting + " this is " + getIdentity() + " ruler of the wise " + people+"."); } public void sayHelloTo(Ruler otherRuler) //Talk to another ruller { numConversations++; System.out.println(greeting +", " + otherRuler.getIdentityWithCountry()+ ", this is " +title+ " "+name + " and I bring greetings from " + country+ "."); lastSpokenTo = otherRuler; } public void report() //Report on my talking { if (numConversations == 0) //ensures proper grammar used base on the number of conversations (none) System.out.println("This is " + getIdentity() + " and I need someone to talk to!"); else if (numConversations == 1) // Only 1 conversation System.out.println("This is " + getIdentity() + " and I have started only " + numConversations + " conversation. The last person I spoke to was " + lastSpokenTo.getIdentity()+"."); else //Multiple conversations System.out.println("This is " + getIdentity() + " and I have started " + numConversations + " conversations. The last person I spoke to was " + lastSpokenTo.getIdentity()+"." ); } }