Summary: lets practice with files and go routines, making a multithreaded fortune program
Due: Tuesday Feb 20th at 11:59pm (the day before our Monday on Wednesday class)
This one will go into your
project grade this time.
Create a new project. Make sure it has your name in it somewhere in the project name.
(granted I am pushing the limits to try and get a simple program which also practices with channels and goroutines)
Write go go program that has two functions
The main function will
create a channel and then spawn the fortune function as a go routine taking the channel as a parameter.
Enter a forever loop and ask the user if they want another fortune. If the user says yes (with any capitalization) then send a message down the channel to the for the fortune function to select a fortune and display it.
If the user answers no (with any capitalization), then end the program
if the user answers anything else, then ask again
The fortune function will
Open the fortunes.txt file and read it in.
split the contents of the fortunes file on the %% string to get a slice of strings
loop forever
wait for a message on the channel
when a message is received, randomly select one of the fortunes from your slice
and print it to the screen.
Using goroutines and channels will feature heavily in this project’s grading
submit the project by putting it on github and sending me a collaboration invite. As before.
the min/max opportunity of the month