Question: Code for random date import java.time.LocalDateTime; import java.util.Random; public class RandomDate { static public LocalDateTime lastDateTime = null; static public Random rand = new Random();

Code for random date

import java.time.LocalDateTime; import java.util.Random; public class RandomDate { static public LocalDateTime lastDateTime = null; static public Random rand = new Random(); /** * Get the next LocalDateTime. First time this will be the * current date/time. Every subsequent call will return a * LocalDateTime at least 2 minutes later and at most one hour later. */ public static LocalDateTime next() { if (lastDateTime == null) { lastDateTime = LocalDateTime.now(); } else { lastDateTime = lastDateTime.plusMinutes(2 + (int) (rand.nextDouble() * 58)); } return lastDateTime; } /** * A simple main to test RandomDate. Prints the LocalDateTime from * 10 calls to next(). * * @param args not used. */ public static void main(String[] args) { System.out.println(next()); System.out.println(next()); System.out.println(next()); System.out.println(next()); System.out.println(next()); System.out.println(next()); System.out.println(next()); System.out.println(next()); System.out.println(next()); System.out.println(next()); System.out.println(next()); } }

Specialized boards/forums, such as stack overflow and techiest forums, provide a means for individuals to ask technology questions and solicit answers. Others may then post their answers. All communication in a forum is typically performed on-line and recorded. For this assignment it is desired to provide reports of all communication that has been recorded in a forum. Since the report is to be printed on paper that has a fix width, the text of a post needs to be printed in a word wrapped format. Furthermore, answers need to be printed with 4 space indentation.

Develop classes to represent a forum, questions, answers, and members. A forum is to have a short one line title to the forum, and the member owning the forum. Have the constructor for a member consists of ONE argument which is the members full name (i.e., first name followed by and optional middle initial and then a last name). A question contains a subject line, content (which can be a very long string of text), the member creating the question, and the date/time it was posted. An answer contains a member providing an answer, an answer (which can be a very long string of text), and a date/time the answer was posted. Note a forum can have many questions, and each question can have many answers.

In your forum class provide two print methods, one to print a summary of questions and the other to print the entire contents. A sample for the report produced by the summary is as follows:

Assignment Discussion Forum Summary Report

Owned by: David T Smith No Questions: 3

Questions By #As On ----------------------------- --- --- ---------------- 0 or blank BTJ 3 2/16/15 08:30pm Problems with formatting. CJH 1 2/12/15 01:52pm Reminder javadoc and format DTS 0 2/07/15 04:59pm For this report: The number of columns is 60. The title for the forum is to be printed in the center of the page. If needed, truncate the length of the subject line of a post to 30 characters. The first By is the initials of the member posting the quetion. #Rs is the total number of replies. The On is the date and time of the initial question. This report does not show the replies themselves. A sample detail report would be:

Assignment Discussion Forum Detail Report

Owned by: David T Smith No Questions: 3

Questions ------------------------------------------------------------ 0 or blank by B. Blue on 2/16/15 08:30pm

When printing the time logs does it matter if we have a 0 or do you want a blank space in the overtime column? ------------------------------------------------------------ Re: 0 or blank by D. Smith on 2/16/15 08:32pm I want to see a blank printed when the number of hours is zero. Consider using %3s in the format string and using the ternary operator when providing a value for the argument. -------------------------------------------------------------- Re: 0 or blank by B. Blue 2/16/15 08:35pm To print a simple space or blank, Could I just do a simple if statement to print one form or another. -------------------------------------------------------------- Re: 0 or blank by J. Green 2/16/15 08:50pm An if could be used, but I think:

n == 0 ? "" : String.valueOf(n)

Would be simpler ------------------------------------------------------------ Problems with formatting. by C. Hope on 2/12/15 01:52pm

I can't get normal hours to print. My code inside my print method:

System.out.printf("Normal Hours worked: %50d ", timeLog.getNormalHours() ) ; ------------------------------------------------------------ Re: Problems with formatting. by D. Smith on 2/13/15 04:52am Not sure what your problem is. The %50d looks odd. Should it be more like %5d? That is only 5 digits wide not 50. ------------------------------------------------------------ Reminder javadoc and formatting by D. Smith on 2/07/15 04:59pm Reminder, Make sure you have javadoc before the class declaration and before every public method. Make sure you Use good formatting. ------------------------------------------------------------

For this report: The number of columns is 60. The content of the question/question must be separated into paragraphs with each paragraph word wrapped. A new line character (i.e. ) is used to separate paragraphs. An answer must have a left margin which is a 4 space indent from its question. If needed, truncate the length of the subject line to the remaining width of a page. Likewise for the by line. Note the by line lists only the members first initial and last name.

To assist in this assignment, a class called RandomDate is available on the T:\ cosc210. This class has a static method next() which will generate simulation data where the returned LocalDateTime is 2 minutes to one hour later than the previous call.

Additional specification: Create a class TextWrapper. The TextWrapper is to have two static methods printWrap(String text, int leftMargin, int rightMargin) printCentered(String text, int rightMargin)

printWrap is to print the text as a set of word wrapped paragraphs between the left and right column margins. Text composing paragraphs are separated by new line characters in the input text parameter. When printing the paragraphs are separated by blank lines. The printDetailReport method in forum must use this class to print the word wrapped content. printCentered is to print the text on a line centered between a left margin of 0 and the specified right margin. When printing the reports, use this method to print the first header lines. Use RandomDate for the date of the questions and replies. Do not pass it in as an argument in the constructor. Instead create a new RandomDate instance inside the constructor. In the forum define an addQuestion method which takes as an argument a member, a subject line, and a content string (which could be very long). Have the method create an instance of a question and add it to the array. Return the instance of the question. (this will allow the test program to add replies to the replies) In the question class provide an addAnswer method which takes as an argument a member and a content string. Have the method create an instance of an answer and add it to the array. Use the questions subject line to generate the subject line for the answer. In your forum, have a private method that will print the first 5 lines of a report (these are the same between the two reports except for the second line). Call the method from the other two report methods to print the report header. No print should appear after the 60th column. Abide by good programming practices (e.g., naming conventions, javadoc, indentation, use of braces, etc.).

Write a test program to test the TextWrapper class.

Write a test program to thoroughly test your forum classes. You do not need to use the example above (if you do the dates will at least be different). However, make sure your example has: At least 3 posts to the forum One post to the forum has no replies One post to the forum has at least 2 replies For replies use a subject line the subject line to which it is a reply pre-pended with Re: . Print both a summary report and a detailed report One forum is sufficient

Bonus 10 points. Allow answers to be posted to answers. That is answer to answer, answer to answers to answers, and so forth. The summary report the number answers (#As) is to include all answers to the questions not just the immediate answers. The detail report is to show answers to answers indented an additional 4 spaces to the parent answer. The title is the have RE: prepended to the parent answer.

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!