{"id":236989,"date":"2018-02-20T23:50:30","date_gmt":"2018-02-20T23:50:30","guid":{"rendered":"http:\/\/essaysparlor.com\/programming-assignment-3-email-twitter-and-inheritancejava-assignment\/"},"modified":"2018-10-24T09:05:31","modified_gmt":"2018-10-24T09:05:31","slug":"programming-assignment-3-email-twitter-and-inheritancejava-assignment","status":"publish","type":"post","link":"https:\/\/www.benedictsol.com\/blogs\/programming-assignment-3-email-twitter-and-inheritancejava-assignment\/","title":{"rendered":"Programming Assignment 3 &#8211; Email, Twitter and Inheritance\/JAVA ASSIGNMENT"},"content":{"rendered":"<p>Programming Assignment 3 &#8211; Email, Twitter and Inheritance\/JAVA ASSIGNMENT<\/p>\n<p>This assignment is designed to test your understanding of inheritance in Java.  The key concept is writing inheritance hierarchies.<br \/>\nUnderstand the Classes and Problem Every message contains some content (&#8220;The British are coming!  The British are coming!&#8221; and a creator, or author (&#8220;Paul Revere&#8221;).<\/p>\n<p>We could enhance these by adding other traits (date and\/or time of creation), but let&#8217;s keep things simple and say that these are the only two aspects of a basic<\/p>\n<p>message. Some messages, however, have further components that define them.  For example, an email consists of a normal message, plus at least two other items:  a from<\/p>\n<p>email address and a to email address.  An email is a message, but a special kind of message.  So, we can smell inheritance in the neighborhood.  A message seems like<\/p>\n<p>it will make a good base class, and an email, having an is a relationship with message, is a good candidate for a derived class or extension of the base class message.<\/p>\n<p>Meanwhile, a tweet consists of a normal message, plus at least one other item:  a from user id.  An tweet is a message, too.  It has a different kind of specialization<\/p>\n<p>than an email has, so it is a different extension of the base class. (We are not considering a direct tweet, which would also require a to user id.) Not only will both<\/p>\n<p>emails and tweets contain extra data than the base class, message, but in at least one instance we will see the same member (the content) have a different kind of<\/p>\n<p>restriction in the derived class than in the base class (can you guess what I&#8217;m suggesting before you read on?).  Thus, even though we store the tweet content in the<\/p>\n<p>base class member, without the need for a new content area for the tweet, we will still have a different validation of the length of that message content. The Base<\/p>\n<p>Class: Message Your base class is named Message. Public or Protected (your choice) Static Class Constants Define a full set of limits and defaults, like MAX_MSG_LENGTH<\/p>\n<p>and DEFAULT_AUTHOR, for both min, max lengths and default data of every member.  Set the maximum message length to a large number (at least a million) and the maximum<\/p>\n<p>author length to a reasonable value like 40 or 65, not 5 or 200. Private Member Data<br \/>\nString message; String author; Public Methods \ufffd\ufffd\ufffd Default and 2-parameter constructors. \ufffd\ufffd\ufffd Mutator and Accessor for each member. \ufffd\ufffd\ufffd a toString() method that provides a<\/p>\n<p>nicely formatted return String for potential screen I\/O.<br \/>\nCS 1B                                                                                                Assignment #3 Winter 2017                             January 24,<\/p>\n<p>2017  _________________________________________________________________________________________________________<br \/>\nPage 2 of 5<br \/>\nPrivate Methods \ufffd\ufffd\ufffd private static validation helpers to filter client parameters.   The Derived Class: Email Your first derived class is named Email.  Email uses the<\/p>\n<p>two members already present in the base class;  the Email&#8217;s message is the message of the base class, and the author of the base class is the Emails\ufffd\ufffd\ufffd author&#8217;s actual<\/p>\n<p>name (not the from email address which I will introduce next).  Do not try to store an Email&#8217;s message body or author as a new member of the derived class.<\/p>\n<p>Duplicating base class data in derived class means you do not understand what inheritance is, thus the significance of this kind of mistake. Public Static Class<\/p>\n<p>Constants To the existing base class statics, add at least two with names and meanings similar or identical to MAX_EMAIL_ADDRESS_LENGTH and DEFAULT_EMAIL_ADDRESS.<\/p>\n<p>Look up the maximum length of an email address, and make yours is no larger than that (but you can make is smaller for easier testing). Additional Private Member Data<br \/>\nString fromAddress; String toAddress; Public Methods \ufffd\ufffd\ufffd Default and 4-parameter constructors. Use constructor chaining. \ufffd\ufffd\ufffd Mutator and Accessor for the new members. \ufffd\ufffd\ufffd<\/p>\n<p>Override those methods of the base class for which it makes sense to do so.  Think about this and come to your own conclusions. Private Methods \ufffd\ufffd\ufffd private static<\/p>\n<p>validation helper to filter a bad email address.  You should do the minimum, but you don&#8217;t have to be more complete than that.  This is just to show that you can<\/p>\n<p>perform basic filtering.  The minimum is a method isValidEAddr() (or similarly named) which tests for both length and the existence of at least one &#8216;@&#8217; and one &#8216;.&#8217;<\/p>\n<p>character.  Further is up to you, but don&#8217;t overdo it or be too restrictive. The Derived Class: Tweet \ufffd\ufffd\ufffd Tweet uses the two members already present in the base class;<\/p>\n<p>The Tweet&#8217;s message is the message of the base class, and the author of the base class is the Tweet&#8217;s author&#8217;s actual name.   Public Static Class Constants \ufffd\ufffd\ufffd To the<\/p>\n<p>existing base class statics, add three with a names and meaning similar or identical to MAX_TWITTER_ID_LENGTH (15), MAX_TWEET_LENGTH (140) and DEFAULT_USER_ID.  Look<\/p>\n<p>up and use the actual maximum lengths of the first two constants. \ufffd\ufffd\ufffd While the MAX_TWEET_LENGTH is going to be smaller than the base class&#8217;s MAX_MSG_LENGTH, do not<\/p>\n<p>assume this fact in your implementation.  A valid message length for a Tweet has to be smaller than both of these values.  If it&#8217;s not a valid base class message, it<\/p>\n<p>isn&#8217;t a valid Tweet message, and this should be true if we later change the MAX_TWEET_LENGTH length to be 50 million.<br \/>\nCS 1B                                                                                                Assignment #3 Winter 2017                             January 24,<\/p>\n<p>2017  _________________________________________________________________________________________________________<br \/>\nPage 3 of 5<br \/>\nAdditional Private Member Data<br \/>\nString fromID; Public Methods \ufffd\ufffd\ufffd Default and 3-parameter constructors. When it is possible and meaningful, use constructor chaining. Think about which constructor to<\/p>\n<p>chain to. \ufffd\ufffd\ufffd Mutator and Accessor for the new member. \ufffd\ufffd\ufffd Override those methods of the base class for which it makes sense to do so.  Think about this and come to your<\/p>\n<p>own conclusions.  You have to somehow enforce the length limits of both the base class and the derived class for the same message member. Private Methods \ufffd\ufffd\ufffd private<\/p>\n<p>static validation helpers (plural) to filter out bad tweets and Twitter IDs.   \ufffd\ufffd\ufffd Create an  isValidTweet() for the message.  \ufffd\ufffd\ufffd  Create an isValidTwitterID() for the<\/p>\n<p>Twitter ID.   \ufffd\ufffd\ufffd Make a third, even lower-level, helper that would make isValidTwitterID() clear and short. This helper- helper should be named something like<\/p>\n<p>stringHasOnlyAlphaOrNumOrUnderscore()  and that name tells you the kind of thing it should do: it should make sure the Twitter ID contains only some combination of<\/p>\n<p>letters, numbers or an underscore (&#8216;_&#8217;).<br \/>\nThe Driver Class: MessageDriver Create several sample objects of type Message, Email, and Tweet in your main method. \ufffd\ufffd\ufffd Instantiate two or more Message objects, some<\/p>\n<p>using the default constructor and some using the parameter-taking constructor.  Mutate one or more of the members, and after that use the toString() to assist a screen<\/p>\n<p>output so we can see what all of your objects contain.  Next, test one or more accessors.  Finally, test two or more mutators, providing both legal and illegal<\/p>\n<p>arguments and testing the return values (thus demonstrating that the mutators do the right thing).  Here is a sample run from my test (but you will have to<\/p>\n<p>imagine\/deduce the source I used and create your own source for your testing, which will produce a different output). \ufffd\ufffd\ufffd Recommended test of  Class Email Similar to the<\/p>\n<p>Message class. \ufffd\ufffd\ufffd Recommended test of  Class Tweet Similar to the Message class.<br \/>\nCS 1B                                                                                                Assignment #3 Winter 2017                             January 24,<\/p>\n<p>2017  _________________________________________________________________________________________________________<br \/>\nPage 4 of 5<br \/>\nSample Run:<br \/>\nBase Class Testing ****************************** Author: Smith  Message &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-  Some messages just aren&#8217;t worth sending.<br \/>\nAuthor: Johnson  Message &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-  hello world testing Message accessors: Smith<br \/>\nhello world<br \/>\ntesting Message mutators: too long (as expected) Author: Smith  Message &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-  Some messages just aren&#8217;t worth sending.<br \/>\nacceptable length (shoud  be) Author: Smith  Message &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-  LONG STRING abcde abcde abcde abcde  abcde abcde abcde  abcde  abcde  abcde  abcde abcde<\/p>\n<p>abcde  abcde abcde abcde<br \/>\nDerived Email Testing ***************************<br \/>\nFrom: lili999@gmail.com To: chloe123@gmail.com.com Author: lili koi  Message &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-  Arf, arf, arf, arf &#8230;&#8230;.. arf<br \/>\nFrom: chloe123@gmail.com To: lili999@gmail.com Author: Liza  Message &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-  bark bark<br \/>\ntesting EMail accessors: lili999@gmail.com<br \/>\nlili999@gmail.com<br \/>\n testing Email mutators: too long (as expected) From: lili999@gmail.com<br \/>\nCS 1B                                                                                                Assignment #3 Winter 2017                             January 24,<\/p>\n<p>2017  _________________________________________________________________________________________________________<br \/>\nPage 5 of 5<br \/>\nTo: chloe123@gmail.com.com Author: lili koi  Message &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-  Arf, arf, arf, arf &#8230;&#8230;.. arf<br \/>\nmissing @ char (as expected) From: lili999@gmail.com To: chloe123@gmail.com.com Author: lili koi  Message &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-  Arf, arf, arf, arf &#8230;&#8230;.. arf<br \/>\nmissing DOT char (as expected) From: lili999@gmail.com To: chloe123@gmail.com.com Author: lili koi  Message &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-  Arf, arf, arf, arf &#8230;&#8230;.. arf<br \/>\nDerived Tweet Testing ***************************<br \/>\ntesting Tweet mutators: bad Twitter ID (as expected) Tweet: Matt Johnson @Mattcsu Hello From Foothill college<br \/>\nacceptable Twitter ID (as expected) Tweet: Matt Johnson @a_good_user99 Hello From Foothill college Submission Instructions \ufffd\ufffd\ufffd Execute the program and copy\/paste the<\/p>\n<p>output that is produced by your program into the bottom of the source code file, making it into a comment. I will run the programs myself to see the output. \ufffd\ufffd\ufffd Make<\/p>\n<p>sure the run &#8220;matches&#8221; your source. If the run you submit could not have come from the source you submit, it will be graded as if you did not hand in a run. \ufffd\ufffd\ufffd Use the<\/p>\n<p>Assignment Submission link to submit the source code file.  \ufffd\ufffd\ufffd Submit the following files: o Message.java o Email.java o Tweet.java o MessageDriver.java \ufffd\ufffd\ufffd Submit a zip<\/p>\n<p>file containing your java file(s). Include your name in the name of the zip file.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Programming Assignment 3 &#8211; Email, Twitter and Inheritance\/JAVA ASSIGNMENT This assignment is designed to test your understanding of inheritance in Java. The key concept is writing inheritance hierarchies. Understand the Classes and Problem Every message contains some content (&#8220;The British <a href=\"https:\/\/www.benedictsol.com\/blogs\/programming-assignment-3-email-twitter-and-inheritancejava-assignment\/\" class=\"read-more\">Read More &#8230;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-236989","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/posts\/236989","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/comments?post=236989"}],"version-history":[{"count":0,"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/posts\/236989\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/media?parent=236989"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/categories?post=236989"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/tags?post=236989"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}