Advertisement
Guest User

Untitled

a guest
May 8th, 2019
731
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.07 KB | None | 0 0
  1.  
  2. public class Foothill {
  3.    
  4.     public static void main(String[] args) {
  5.         Message message1, message2, message3;
  6.        
  7.         message1 = new Message();
  8.         message2 = new Message("hello ok hi bye");
  9.         message3 = new Message("123");
  10.        
  11.         System.out.println(message1.toString());
  12.         System.out.println(message2.toString());
  13.         System.out.println(message3.toString());
  14.        
  15.         message1.setMessage("i just set a new message, that's cool!");
  16.         message2.setMessage("hi");
  17.         message3.setMessage("alright, is this message long enough for you??");
  18.        
  19.         System.out.println(message1.toString());
  20.         System.out.println(message2.toString());
  21.         System.out.println(message3.toString());
  22.        
  23.         Email email1, email2, email3;
  24.        
  25.         email1 = new Email();
  26.         email2 = new Email("this is your message to me", "bob@gmail.com",
  27.                 "thatonefriend@gmail.com");
  28.         email3 = new Email("whoa", "@.", "amazing@gmail.com");
  29.        
  30.         System.out.println(email1.toString());
  31.         System.out.println(email2.toString());
  32.         System.out.println(email3.toString());
  33.        
  34.         System.out.println("\ntesting Email accessors:");
  35.         System.out.println(email2.getFromAddress());
  36.         System.out.println(email2.getToAddress());
  37.        
  38.         System.out.println("\ntesting Email mutators:");
  39.         if (email3.setFromAddress("john.wick@continental.com")) {
  40.             System.out.println("  successfully set email as "
  41.                     + email3.getFromAddress());
  42.         }
  43.         else {
  44.             System.out.println("  failed so set email");
  45.         }
  46.        
  47.         if (email3.setToAddress("aa@gmail.com")) {
  48.             System.out.println("  successfully set email as "
  49.                     + email3.getToAddress());
  50.         }
  51.         else {
  52.             System.out.println("  failed so set email");
  53.         }
  54.        
  55.         Shweet shweet1, shweet2, shweet3;
  56.        
  57.         shweet1 = new Shweet();
  58.         shweet2 = new Shweet("fasfd", "whoa");
  59.         shweet3 = new Shweet("Netflix. This is definitely going to spoil it, so be warned). In this film, the development of the character Stefan and the plot of his story is dictated by viewer choices, allowing for multiple endings. Stefan is a game creator, designing a game based on the choose your own adventure book, Bandersnatch. The book itself is a symbol for madness, as the author of it himself is insane, having murdered his family and himself because of his obsession with his work. In one of the endings, Stefan himself also follows the same fate of Bandersnatchs author. However, it is curious how he ends up on such a path. The viewer has to selectively choose paths that cut Stefan off from the world, as if Stefan was indeed paranoid. He himself fears his therapist, his father, and his coworkers, so by choosing to remove him from society, his paranoia erupts into the forefront of his mind, creating hallucinations and stressing his mental state to the point of literal insanity.  What is interesting however, is that this theme is similarly present in much of the gothic literature we have read for this unit. Paranoia is developed, grown, and ultimately becomes the main motivation of action and tho", "g");
  60.        
  61.         System.out.println(shweet1.toString());
  62.         System.out.println(shweet2.toString());
  63.         System.out.println(shweet3.toString());
  64.  
  65.     }
  66. }
  67.  
  68.  
  69. class Message {
  70.    
  71.     //define class constants, protected so subclasses can access
  72.     protected static final int MIN_MSG_LENGTH = 1;
  73.     protected static final int MAX_MSG_LENGTH = 100000;
  74.     protected static final String DFLT_MSG = "default_message";
  75.     protected static final String MSG_BORDER = "\n Message -------------------";
  76.     protected static final String NEW_LINE = "\n";
  77.     //define private member data
  78.     private String message;
  79.    
  80.     public Message() {
  81.         message = DFLT_MSG;
  82.     }
  83.    
  84.     public Message(String message) {
  85.         setMessage(message);
  86.        
  87.     }
  88.    
  89.     public boolean setMessage(String message) {
  90.         if (!isValidMessage(message)) {
  91.             this.message = DFLT_MSG;
  92.             return false;
  93.            
  94.         }
  95.        
  96.         this.message = message;
  97.         return true;
  98.     }
  99.    
  100.     public String getMessage() {
  101.         return message;
  102.     }
  103.    
  104.     public String toString() {
  105.         return MSG_BORDER + NEW_LINE + message + NEW_LINE;
  106.     }
  107.    
  108.     private static boolean isValidMessage(String message) {
  109.         if (message.length() < MIN_MSG_LENGTH ||
  110.                 message.length() > MAX_MSG_LENGTH) {
  111.             return false;
  112.         }
  113.        
  114.         return true;
  115.     }
  116. }
  117.  
  118.  
  119.  
  120. class Email extends Message {
  121.    
  122.     public static final int MIN_EMAIL_ADDRESS_LENGTH = 3;
  123.     public static final int MAX_EMAIL_ADDRESS_LENGTH = 254;
  124.     public static final String DFLT_EMAIL_ADDRESS = "default@gmail.com";
  125.     public static final String FROM_HEADER = "From: ";
  126.     public static final String TO_HEADER = "To: ";
  127.    
  128.     private String fromAddress;
  129.     private String toAddress;
  130.    
  131.     public Email() {
  132.         super();
  133.         fromAddress = DFLT_EMAIL_ADDRESS;
  134.         toAddress = DFLT_EMAIL_ADDRESS;
  135.     }
  136.    
  137.    
  138.     public Email(String message, String fromAddress, String toAddress) {
  139.         super(message);
  140.         setFromAddress(fromAddress);
  141.         setToAddress(toAddress);
  142.        
  143.     }
  144.    
  145.     public boolean setFromAddress(String emailAddress) {
  146.         if(!isValidEmailAddress(emailAddress)) {
  147.             fromAddress = DFLT_EMAIL_ADDRESS;
  148.             return false;
  149.         }
  150.        
  151.         fromAddress = emailAddress;
  152.         return true;
  153.     }
  154.    
  155.     public boolean setToAddress(String emailAddress) {
  156.        
  157.         if(!isValidEmailAddress(emailAddress)) {
  158.             toAddress = DFLT_EMAIL_ADDRESS;
  159.             return false;
  160.         }
  161.        
  162.         toAddress = emailAddress;
  163.         return true;
  164.        
  165.     }
  166.    
  167.     public String getFromAddress() {
  168.        
  169.         return fromAddress;
  170.        
  171.     }
  172.    
  173.     public String getToAddress() {
  174.        
  175.         return toAddress;
  176.        
  177.     }
  178.    
  179.     public String toString() {
  180.        
  181.         String output;
  182.         output = FROM_HEADER + fromAddress + "\n" + TO_HEADER + toAddress;
  183.  
  184.         return output + super.toString();
  185.        
  186.        
  187.        
  188.     }
  189.    
  190.     //private static validation helper method for the main constructor,
  191.     //utilizes two helper methods containsEssentialChars and
  192.     //validateEmailAddressBody
  193.     private static boolean isValidEmailAddress(String emailAddress) {
  194.        
  195.         if (!containsEssentialChars(emailAddress) ||
  196.                 !validateEmailAddressBody(emailAddress) ) {
  197.             return false;
  198.         }
  199.        
  200.         return true;
  201.        
  202.     }
  203.    
  204.     //private static helper method that checks to see if email address
  205.     //contains the essential chars '@' and '.'
  206.     private static boolean containsEssentialChars(String emailAddress) {
  207.        
  208.         return emailAddress.contains("@") && emailAddress.contains(".");
  209.        
  210.     }
  211.    
  212.     //private static helper method that checks length of actual address rather than
  213.     //include the @gmail.com or @whatever.com part
  214.     private static boolean validateEmailAddressBody(String emailAddress) {
  215.        
  216.         //separates the actual address of the email, ex. "myname@gmail.com"
  217.         //would produce the string "myname"
  218.         String emailAddressBody =
  219.                 emailAddress.substring(0, emailAddress.indexOf('@'));
  220.        
  221.         if (emailAddressBody.length() < MIN_EMAIL_ADDRESS_LENGTH ||
  222.                 emailAddressBody.length() > MAX_EMAIL_ADDRESS_LENGTH) {
  223.             return false;
  224.         }
  225.         else {
  226.             return true;
  227.         }
  228.        
  229.     }
  230.  
  231. }
  232.  
  233.  
  234. class Shweet extends Message {
  235.    
  236.     public static final int MAX_SWHITTER_ID_LENGTH = 15;
  237.     public static final int MAX_SHWEET_LENGTH = 140;
  238.     public static final String DEFAULT_USER_ID = "defaultID";
  239.    
  240.     private String fromID;
  241.    
  242.     public Shweet() {
  243.         super();
  244.         fromID = DEFAULT_USER_ID;
  245.     }
  246.    
  247.     public Shweet(String message, String fromID) {
  248.         setMessage(message);
  249.        
  250.         setFromID(fromID);
  251.     }
  252.    
  253.     public boolean setFromID(String userID) {
  254.         fromID = userID;
  255.         return true;
  256.     }
  257.     ///VFIX
  258.     public String getFromID() {
  259.        
  260.         return fromID;
  261.        
  262.     }
  263.    
  264.     public String toString() {
  265.        
  266.         return "Shweet: @" + fromID + "\n" + super.getMessage();
  267.        
  268.     }
  269.    
  270.     public boolean setMessage(String message) {
  271.         if(!isValidShweet(message)) {
  272.             System.out.println("not falivd: "  + message);
  273.             super.setMessage(DFLT_MSG);
  274.             return false;
  275.         }
  276.        
  277.         super.setMessage(message);
  278.         return true;
  279.     }
  280.     private static boolean isValidShweet(String message) {
  281.        
  282.         if (message.length() < MIN_MSG_LENGTH ||
  283.                 message.length() > MAX_SHWEET_LENGTH) {
  284.             return false;
  285.         }
  286.        
  287.         return true;
  288.     }
  289.    
  290.     private static boolean isValidShwitterID(String userID) {
  291.         return true;
  292.     }
  293.    
  294.     private static boolean stringHasOnlyAlphaOrNumOrUnderScore(String message) {
  295.        
  296.         for(int i = 0; i < message.length(); i++) {
  297.            
  298.         }
  299.         return true;
  300.     }
  301. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement