Question: I am running into problems with storing the postIDS on POST _ LIST _ FILENAME. Everytime it tries to add a file it shows this
I am running into problems with storing the postIDS on POSTLISTFILENAME. Everytime it tries to add a file it shows this error java.lang.NumberFormatException: For input string: any helo would be greatly appreciated!
A TextBook manages a collection of Posts for the TextBook social media site.
All Post IDs are recorded in a file with the name specified in constant
POSTLISTFILENAME. A TextBook must implement this interface as follows:
public class TextBook implements TextBookInterface
In addition to the methods listed below, a TextBook is expected to have a single
constructor with no parameters. When instantiated, a TextBook attempts to restore
the previous session from files. If it is unable to do so it initiates a new
empty list of Posts and sets the last post ID to zero. This constructor has
signature:
public TextBook
public interface TextBookInterface
This constant defines the expected name of the file that contains a
list of all Post IDs in the TextBook, one ID per line.
public static final String POSTLISTFILENAME "postIDs.txt;
Return the last Post ID assigned to a Post in TextBook. If TextBook has
just been loaded, this number corresponds to the last ID read from file
POSTLISTFILENAME or if the file was not found.
@return current value of lastID
public int getLastID;
Return the number of Posts currently in TextBook's collection.
@return current number of Posts
public int getPostCount;
square
itself and its comments. You may assume the index is in bounds.
@param index index of Post
square@return toString from Post at given index
@throws IndexOutOfBoundsException
public String getPostStringint index;
square Increments the value of last ID This becomes the ID for the new Post.
Adds a new Post with the given author and text to the TextBook and appends
the new ID to file POSTLISTFILENAME.
@@param author name of the new Post's author
@@araram text text of the new Post
public void addPostString author, String text;
Removes and returns the Post at the given index. Rewrites file
POSTLISTFILENAME to include only the IDs of Posts still in the collection.
You may assume the index is in bounds.
@param index the index of a Post in TextBook's collection
@return removed Post
@throws IndexOutOfBoundsException
public Post removePostint index;
Adds a new comment with the given author and text to the Post at the given
index. You may assume the index is in bounds.
@param postIndex index of post targeted by this comment
@param author name of comment's author
@param text text of the comment
@throws IndexOutOfBoundsException
public void addCommentint postIndex, String author, String text;
Returns a wellformatted String with the current number of Posts and a list
of Posts where each Post's toStringPostOnly is preceded by its index in the
collection and each Post is on its own line as shown in the example.
Example:
"TextBook contains posts:
T::Z Mason Did stuff.
T::Z Luke Heckled Mason."
@return wellformatted String with post count and indexed posts
public String toString;
Returns a COPY of the posts list for testing. Make sure you are not violating
encapsulation by directly returning the posts variable or an alias of the
posts variable.
Note that a copy of the list still violates ideal encapsulation because we're
not performing a 'deep' copy of the Post objects themselves. However, this is
adequate for testing purposes.
@return copy of posts list
public ArrayList getPosts;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
