Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

looks like more than it really is. please help This program defines a class for

ID: 3803911 • Letter: L

Question

looks like more than it really is. please help

This program defines a class for BlogEntry, which can be used to store an entry for a web log. The class tracks the poster's username, text of the entry, and date posted using the Date class defined in this chapter Display 4.13(Date.java from the book examples). 2. To test the BlogEntry class the project will define another class called BlogEntryTester that will create BlogEntry objects using data read from a file. 3. BlogEntry Class a. Stores Blog Entry information. b. Instance Variables i. String username – name of the blogger ii. Date dateOfBlog – date of the blog iii. String blog – the text of the blog iv. All instance variables are private. c. Constructors i. No-Argument or default constructor (see Pet class Display 4.15, Pet( ) as an example) . ii. Parameterized constructor, (see Pet class Display 4.15, Pet(String initialName, int initialAge, double initialWeight) as an example) 1. Parameters include user’s name, date of blog and blog text.   2. Uses the parameters to set the appropriate instance variables.
d. Methods i. Accessor methods (See Pet class for examples.) 1. String getUsername( ). 2. Date getDateOfBlog( ). 3. String getBlog( ). ii. Mutator methods (See Pet class for examples.) 1. void setUsername(String … ) 2. void setDateOfBlog(Date …) 3. void setBlog(String …) iii. String getSummary() method 1. Returns up to the first ten words of the entry as a summary of the entry. If the entry has 10 words or less, the method returns the entire entry. 2. Possible logic - The String classes' indexOf method can find the position of a space. Use this along with a looping construct to find the first 10 words. iv. String toString() method 1. Returns a nicely formatted String of all the data in object. 2. Use the accessor method to populate the returned String, do not just access the instance variables directly 3. Example String:
Author: Joey
Date posted: April 16, 2013
Text body: I went to The Masters last week, it was fantastic.
v. Remember all methods are public. 4. BlogEntryTester a. This class will be used to test the BlogEntry Class. It will include the main method that starts the Java application b. Class Requirements i. Create at least two BlogEntry objects, one using the default constructor and the other using the parameterized constructor. ii. Directly or indirectly test all methods of the BlogEntry class.
1. Indirect testing would include testing the accessor method by calling the toString method, since the toString subsequently calls the accessor methods. 2. Use the object created by the default constructor to set the instance variables using the mutator method. 3. Call the getSummary method at least twice, once with a BlogEntry object with 10 words or greater and once with a BlogEntry object with more than 10 words.

Explanation / Answer

Here is the code for the question. By the way since Date.java from the textbook is not available to me, I used the built in Java Date class. Therefore in the code I have commented out the import line for Date. Please use the Date.java form textbook and use its constructor to create Date objects. Just type in the contents from textbook into a file Date.java. Rest of the code will remain same. Please do rate the answer if it helped . Thank you very much.

BlogEntry.java

//import java.util.Date;
//A class to represent a blog entry - author name, text and date posted
class BlogEntry
{
   private String name;
   private Date date;
   private String text;
   //default constructor to initialize to default values
   public BlogEntry()
   {
       name="";
       date=new Date(1,1,2017);
       text="";
   }
   //parameterized constructor
   public BlogEntry(String pname,String ptext,Date pdate)
   {
       name=pname;
       text=ptext;
       date=pdate;
   }
   //getter and setter methods
   public String getName() {
       return name;
   }
   public void setName(String name) {
       this.name = name;
   }
   public Date getDate() {
       return date;
   }
   public void setDate(Date date) {
       this.date = date;
   }
   public String getText() {
       return text;
   }
   public void setText(String text) {
       this.text = text;
   }
  
   //returns the summary containing maximum 10 words from the blog text
   public String getSummary()
   {
       String summary="",word;
       int start=0,idx;
       for(int i=1;i<=10;i++)
       {
           idx=text.indexOf(' ',start);
           if(idx==-1)
           {
               word=text.substring(start);
               summary+=word+" ";
               break;
           }
           else
           {
               word=text.substring(start,idx);
               summary+=word+" ";
               start=idx+1;
           }
              
       }
       return summary;
   }
   public String toString()
   {
       return " Author: "+getName()+
               " Date posted: "+getDate()+
               " Text body: "+getSummary();
   }
  
}

BlogEntryTester.java

//import java.util.Date;
//A class to test the BlogEntry class, Creates 2 object using different constructors and mutators and display using toString()
public class BlogEntryTester {

   public static void main(String[] args) {
       //creating object using default constructor
       BlogEntry entry1=new BlogEntry();
       //now calling mutator methods on this object to set values
       entry1.setName("Joey");
       entry1.setDate(new Date( 2014,3,16)); //date year,month,day
       entry1.setText("I went to The Masters last week."); //text with less than 10 words
       System.out.println("The entry1 was created using default constructor and then values set using mutators. "+entry1);
      
       //creating object using parameterized constructor
      
       String name="Henry";
       //creating text entry with more than 10 words
       String text="I learnt to create a Java class. A class can have construtors and other methods. Mutators can change the values.";
       BlogEntry entry2=new BlogEntry(name,text,new Date(20,2,2017));
       System.out.println(" The entry2 was created using parameterized constructor. "+entry2);
      
   }

}

output

The entry1 was created using default constructor and then values set using mutators.

Author: Joey
Date posted: Thu Apr 16 00:00:00 IST 3914
Text body: I went to The Masters last week.

The entry2 was created using parameterized constructor.

Author: Henry
Date posted: Mon Sep 07 00:00:00 IST 1925
Text body: I learnt to create a Java class. A class can