Please help! I need to create a Java class called Headlines, with the following
ID: 3635153 • Letter: P
Question
Please help!I need to 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 bags, in the following order: people, actions, settings: in other words, randomly choose one people string, then randomly choose one action string, then randomly choose one settings string, and print them all out as one string.
- 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.
Here are the file addresses:
/Users/ribbit/Desktop/actions.txt
/Users/ribbit/Desktop/people.txt
/Users/ribbit/Desktop/settings.txt
Thank you!!!
Explanation / Answer
//So I went ahead and made my own text files, tested, and it all works. //Let me know if you have any questions about my implementation. import java.io.*; import java.util.Random; public class HeadLines { private String [] actions, people, settings; private final int LENGTH = 12; private int line; public HeadLines() { line = 0; actions = new String[LENGTH]; people = new String[LENGTH]; settings = new String[LENGTH]; } public void readFiles() throws IOException{ String str; FileReader fr = new FileReader("/Users/ribbit/Desktop/actions.txt"); //FileReader fr = new FileReader("actions.txt"); BufferedReader br = new BufferedReader(fr); str = br.readLine(); while (str != null || lineRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.