Question: Java 1.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

Java

1.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 users 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.

iii.Read the BlogEntry objects data from a file and pass that to the BlogEntry object either when creating the objects or via the mutator methods.

1.See Book Section2.3 and Display 2.12 for information on how to read from a file.

2.The file structure would be: Name, month, day, year, blogtext. Such as Joey Smith, 4, 16, 2013, I went to The Masters last week, it was fantastic

3.See sample file test.dat on elearning.

4.Since the file field are separated (delimited) by comma, you need to inform the Scanner object of this.. Note that you also need to delimit by a new line as well as by a comma. See the Scanner classes useDelimiter method in the Java API for details on how to handle this.

5.Include javadoc class comment following Project Comment Template on the content page.

6.The project requires two files to be turned in BlogEntry.java and BlogEntryTester.java. Please note that during grading we will use our own data file and the Date class defined in this chapter Display 4.13(Date.java from the book examples).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!