Question: Create a Java class called Headlines, with the following elements: Three instance variables that are arrays of type String. Each array should hold at least
Create a Java class called Headlines, with the following elements: Three instance variables that are arrays of type String. Each array should hold at least 12 Strings. The three arrays will hold data read from three different files, described below. A method that opens three input files (named settings.txt, actions.txt and people.txt see attachments) and reads their data into the 3 arrays (put actions in the action bag, etc.) A method that generates and prints out headlines consisting of strings pulled randomly from each of the arrays, in the following order: people actions settings in other words, randomly choose one people string, then one actions string, then one settings string, and print them all out as one string. Each string should be chosen independently: generate a new random index to pull a string from each array. A main method that creates a Headlines object, prints out a headline, then prompts the user to see whether or not to continue; the program should continue to run as long as the user chooses to see more, and terminates when the user chooses to quit. Extra credit options (15 points possible) Generate your own input files; this option will be graded on a purely subjective basis, the criteria being how much the text amuses your instructor (up to 5 points) Keep track of which phrases in each file have been used, and dont re-use them until all phrases have been used (up to 5 points) Allow the user to save any headlines s/he likes in a separate output file (up to 5 points) Quick refresher on file I/O: 1. import java.util.*; // gives access to class Scanner import java.io.*; // gives access to class FileInputStream 2. declare a FileInputStream object to represent an input file; for example, FileInputStream infile; 3. Associate the file with an actual file using the constructor; for example, infile = new FileInputStream(e:\\people.txt); (Note: this can throw a FileNotFoundException) 4. Attach the file to a Scanner object; example Scanner f = new Scanner (infile); 5. You can now read from the file using the same input methods you use with a keyboard Scanner object; when finished reading from a file, close it using the close() method, for example: f.close(); 6. Once the file is closed, you can set your FileInputStream object to refer to a different file, and associate the Scanner with that object. 7. As an alternative to steps 2 4, you can combine the creation of the Scanner object with the creation of an anonymous FileInputStream object, for example: Scanner f = new Scanner(new FileInputStream(e:\\people.txt); Note: Each of the input files contains 12 words or phrases to be read; the last line of each file is a solitary 0 You can use for loops to populate the arrays based on this information, or you can use while loops with (!file.hasNextInt() as end condition).
People:
Donald Trump
Lady Gaga Irate Customer Battery-operated Toy Monkey Pope Francis Ancient Pharoah Iowa Grandmother Partially-dismantled Robot Leading Scientist Computer Hacker FBI Agent Unemployed Astronaut 0
Actions:
Makes Important Discovery Releases the Kraken Befriends Orphan Bear Cub Dances the Hokey-Pokey Uncovers Astonishing Secret Performs Emergency Appendectomy Executes Perfect Triple Toe-loop Sings National Anthem Eats 1000 Hot Dogs Undergoes Amazing Transformation Sells Own Liver Sobs Uncontrollably 0
Settings:
While Running Marathon Atop Mount Everest On National Television Under Suspicious Circumstances Before Breakfast With Garden Tools In Midnight Romp On a Unicycle Like a Boss At the Super Bowl On Cross-Country Tour While Piloting Passenger Jet 0
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
