Question
This question involves a class named FileText that represents a text file. public class FileText { private String fileName; private int fileBytes; private ArrayListString wordList;
This question involves a class named FileText that represents a text file. public class FileText { private String fileName; private int fileBytes; private ArrayListString wordList; // the contents of the text file // constructors not shown // postcondition: calculates the number of bytes in this file and updates // the instance variable fileBytes public void fileSize() { } // precondition: 0 < newWords.length < wordList.size () // postcondition: elements from the newWords array are placed into consecutive // odd index positions of the wordlist ArrayList // postcondition: the value of fileBytes is updated public void mergeWords(String[] newWords) { } // other methods not shown } The wordlist ArrayList stores the words (tokens) found in a text file. Suppose wordlist contains the following elements: [Mary, had, a, little, lamb] The fileSize method; the size of the file is computed in bytes. Each character in a word counts as one byte. In addition, there is a space in between each word, and each of those spaces also counts as one byte. For the example above, the fileSize method would compute 4 + 3 + 1 + 6 + 4 as the sum of the lengths of each String in the ArrayList. The value of fileBytes would be this sum plus 4, because there would be 4 spaces in between the 5 words. For the mergeWords method, assume the values for the newWords array are as follows: {"one", "two", "three"} After the method has executed, fileBytes will have an updated value, and wordlist would contain the following elements: [Mary, one, had, two, a, three, little, lamb] Complete the fileSize and mergeWords methods below. Be sure to include the method headers.
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