Description: In Project 9 we created a spell checker that used both a perfect size and...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Description: In Project 9 we created a spell checker that used both a perfect size and an oversize array of words. The perfect size array stored the common dictionary, which never changed, and the oversize array stored the personal dictionary, which had extra space for the user to add words. One problem with this approach is that the capacity of the oversize array is fixed. If the capacity is too small, the user will run out of space. If the capacity is too large, the program wastes memory. A better approach is to use an oversize array of moderate capacity (say, 10 elements), and if the user runs out of space, construct a new, larger array. This is exactly how the ArrayList class works. If an element is added to a full ArrayList, the existing elements are copied to a larger array with space for the new element. In this project, we will refactor the spell checker to use ArrayLists instead of arrays. This will require us to change the signature and body of each method. When we are finished, the program will work as it did before, but the code will be shorter and easier to understand, since the details of ArrayList objects are hidden (encapsulated) inside the ArrayList class. Objectives: Update the spell checker to use ArrayLists of Strings, rather than normal String arrays. The new version should include the changes listed below. 1. (20 points) Replace the methods readFilePerfect and readFileOversize with a single method named "readFile". This method reads a file with a given name and returns the lines in an ArrayList of Strings. If the file does not exist, readFile creates an empty text file with the given name. 2. (20 points) Refactor the method checkSpelling. The old method checks if a given String can be found in either of two arrays, one perfect size and the other oversize. The new method checks if the String can be found in either of two ArrayLists. 3. (20 points) Refactor the method writeFile. The old method writes each String in an oversize array to a file with a given name. The new method is given an ArrayList of Strings, rather than an oversize array. 4. (20 points) Refactor the main method. Store the common and personal dictionaries in ArrayLists instead of arrays. Call the refactored methods from objectives 1-3 in place of the old methods so that the program works exactly like the original version. (A user of the program will not be able to see a difference.) 5. (10 points) Remove any unnecessary import statements, local variables, and parameters from the program. 6. (10 points) Use meaningful variable names, consistent indentation, and whitespace to make your code readable. Add comments to explain the overall steps of your program. CS 1323/1324, Fall 2020 University of Oklahoma Getting Started: To ensure that everyone starts with a complete version of the original program, we are providing you with our spell checker code. The method signatures must be: ⚫ public static ArrayList<String> readFile(String fileName) ⚫ public static boolean checkSpelling(String word, ArrayList<String> common, ArrayList<String> personal) • public static void writeFile(String fileName, ArrayList<String> list) Hints and Suggestions: 1. Before modifying the code, import it into a new project (along with the common dictionary text file) and check that it runs correctly. 2. Refer to the API documentation for the ArrayList class if you've forgotten the import statement or method signatures. 3. When writing the method readFile, note that it is no longer necessary to count the number of lines in the file. Simply create an ArrayList with the default constructor and add each word as it is read. The capacity of the list will increase automatically. 4. The program needs to sort the personal dictionary and perform binary search on both ArrayLists. The original program used methods of the Arrays class to perform these operations. These methods only work with normal arrays, not ArrayLists. To sort and search ArrayLists, we need to use methods from the Collections class instead. 5. Test each method after you finish changing it. This will require you to comment out the old code in the main method. Eclipse makes this easy: select the code you wish to comment and press CTRL+/. Alternatively, you can use the block comment symbols/* and */. Description: In Project 9 we created a spell checker that used both a perfect size and an oversize array of words. The perfect size array stored the common dictionary, which never changed, and the oversize array stored the personal dictionary, which had extra space for the user to add words. One problem with this approach is that the capacity of the oversize array is fixed. If the capacity is too small, the user will run out of space. If the capacity is too large, the program wastes memory. A better approach is to use an oversize array of moderate capacity (say, 10 elements), and if the user runs out of space, construct a new, larger array. This is exactly how the ArrayList class works. If an element is added to a full ArrayList, the existing elements are copied to a larger array with space for the new element. In this project, we will refactor the spell checker to use ArrayLists instead of arrays. This will require us to change the signature and body of each method. When we are finished, the program will work as it did before, but the code will be shorter and easier to understand, since the details of ArrayList objects are hidden (encapsulated) inside the ArrayList class. Objectives: Update the spell checker to use ArrayLists of Strings, rather than normal String arrays. The new version should include the changes listed below. 1. (20 points) Replace the methods readFilePerfect and readFileOversize with a single method named "readFile". This method reads a file with a given name and returns the lines in an ArrayList of Strings. If the file does not exist, readFile creates an empty text file with the given name. 2. (20 points) Refactor the method checkSpelling. The old method checks if a given String can be found in either of two arrays, one perfect size and the other oversize. The new method checks if the String can be found in either of two ArrayLists. 3. (20 points) Refactor the method writeFile. The old method writes each String in an oversize array to a file with a given name. The new method is given an ArrayList of Strings, rather than an oversize array. 4. (20 points) Refactor the main method. Store the common and personal dictionaries in ArrayLists instead of arrays. Call the refactored methods from objectives 1-3 in place of the old methods so that the program works exactly like the original version. (A user of the program will not be able to see a difference.) 5. (10 points) Remove any unnecessary import statements, local variables, and parameters from the program. 6. (10 points) Use meaningful variable names, consistent indentation, and whitespace to make your code readable. Add comments to explain the overall steps of your program. CS 1323/1324, Fall 2020 University of Oklahoma Getting Started: To ensure that everyone starts with a complete version of the original program, we are providing you with our spell checker code. The method signatures must be: ⚫ public static ArrayList<String> readFile(String fileName) ⚫ public static boolean checkSpelling(String word, ArrayList<String> common, ArrayList<String> personal) • public static void writeFile(String fileName, ArrayList<String> list) Hints and Suggestions: 1. Before modifying the code, import it into a new project (along with the common dictionary text file) and check that it runs correctly. 2. Refer to the API documentation for the ArrayList class if you've forgotten the import statement or method signatures. 3. When writing the method readFile, note that it is no longer necessary to count the number of lines in the file. Simply create an ArrayList with the default constructor and add each word as it is read. The capacity of the list will increase automatically. 4. The program needs to sort the personal dictionary and perform binary search on both ArrayLists. The original program used methods of the Arrays class to perform these operations. These methods only work with normal arrays, not ArrayLists. To sort and search ArrayLists, we need to use methods from the Collections class instead. 5. Test each method after you finish changing it. This will require you to comment out the old code in the main method. Eclipse makes this easy: select the code you wish to comment and press CTRL+/. Alternatively, you can use the block comment symbols/* and */.
Expert Answer:
Answer rating: 100% (QA)
To accomplish the objectives outlined youll need to modify the existing spell checker code to use ArrayLists instead of arrays Below are the modified method signatures and some hints to guide you thro... View the full answer
Related Book For
Modern Systems Analysis And Design
ISBN: 9780134204925
8th Edition
Authors: Joseph Valacich, Joey George
Posted Date:
Students also viewed these programming questions
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
Design a Java class that represents a cache with a fixed size. It should support operations like add, retrieve, and remove, and it should evict the least recently used item when it reaches capacity.
-
Describe the three cases to consider when determining if a cost allocation is beneficial.
-
What is included in the Checkpoint state legislation database?
-
Timothy Monroe opened a law office on January 1, 2017. During the first month of operations, the business completed the following transactions: Jan. 1 Monroe contributed $62,000 cash to the business,...
-
Sage Inc.s staff of accountants finished preparing the financial statements for the most recent year and will meet next week with the companys CEO as well as the Director of Investor Relations and...
-
Lynn Hardt, a management account ant with the Paibec Corporation, is evaluating whether a component, MTR-2000, should continue to be manufactured by Paibec or purchased from Marley Company, an...
-
how do business organize themselves, management structures. in a supply chain world Effect of globalization on Canada. import/ export. how do they measure success between countries. Trade that reduce...
-
For the network of Fig. 7.105, determine: a. IDQ and VGSQ b. VDS c. VD. DO GS (Th) (on) = 4 mA GS
-
Please Solve this by Java 18 6 Question 5c (6 points) - Needle in a Haystack c) bsearch (haystack, 0, haystack.length - 1, 3); 2 4 5 6 7 8 9 12 14 22 23 25 2 4 10 5 6 7 8 9 12 14 22 23 25 2 4 5 6 7...
-
A firm producing Rice has a production function given by: q = KL/3. The rental rate (v) is $8, and the wage rate (w) is $16. a. What is the marginal rate of technical substitution between labor and...
-
You work for a company, which expects to earn at least 7 percent on its projects. The cash flow information for 4 potential projects is described below. Which of the projects would you fund if the...
-
What 3 options do you have when allocating employee wages to expense accounts?
-
Sony and Loews In April 1998, officials at Sony were ecstatic. The Department of Justice (DOJ) had agreed to allow their theater division to acquire a substantial interest in Cineplex Odeon. Under...
-
Read the extract, which is about a universal basic income. Then, drawing upon module material as well, answer the following three questions. 3.1 Outline what is meant by a universal basic income and...
-
How to prepare a 0.1 N solution of NaOH in a 1000 mL volumetric flask of a 1M solution.
-
Why did management adopt the new plan even though it provides a smaller expected number of exposures than the original plan recommended by the original linear programming model?
-
Explain what is meant by Agile Methodologies.
-
Consider the situation you addressed in Problem and Exercise 5-35. Create numeric cost estimates for each of the costs you listed. Calculate the net present value and return on investment. Include a...
-
An organization is in the process of upgrading microcomputer hardware and software for all employees. Hardware will be allocated to each employee in one of three packages. The first hardware package...
-
Which of the following best describes the underlying rationale for a written investment policy statement (IPS)? A. A written IPS communicates a plan for trying to achieve investment success. B. A...
-
Which of the following is least important as a reason for a written investment policy statement (IPS)? A. The IPS may be required by regulation. B. Having a written IPS is part of best practice for a...
-
Which of the following typical topics in an investment policy statement (IPS) is most closely linked to the clients distinctive needs? A. Procedures. B. Investment Guidelines. C. Statement of Duties...
Study smarter with the SolutionInn App