Question
Create a program for simulating the fortune unix command. The file that contains fortunes uses % in a single line to separate fortune statements. The
Create a program for simulating the fortune unix command. The file that contains fortunes uses % in a single line to separate fortune statements. The fortune command mist parse the file and represent in memory and then select at random one statement and print that every time invoked.We assume that the contents of the file fit in memory properly and is not too big.
If empty statement in the fortune file is empty then if that statement is selected at random, an empty string must be printed.
Statements may be multiline and they should be printed verbatim if that is the case.
As an example:
Your fortune is bad today!
%
No Fortune Today! Sorry.
%
Today is a good day...
To play the lottery
%
%
Sorry not much fortune today!
%
There are 5 statements above so your program must parse the file and find that out and store the string in some data structure then select a number between 0 and 4 if 2 is selected the following must be printed:
Today is a good day...
To play the lottery
In java
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started