For all questions in this problem, be sure to follow the design recipe carefully: Give sufficient...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
For all questions in this problem, be sure to follow the design recipe carefully: Give sufficient examples of data, and sufficient tests, to test your methods thoroughly. . If you find yourself wanting to use a field-of-field or getters, stop. Fill out the template for each method, and figure out another design. Think carefully about how to use dynamic dispatch, and where to define methods, to keep your code as simple and clean as possible. Note: The following method defined for the class String may be useful: // does this String come before the given String lexicographically? // produce value < 0 if this String comes before that String // produce value zero // produce value > 0 if this String is the same as that String if this String comes after that String int compareTo(String that) In a future assignment, we will be creating a game that deals with lists of words. A word can be active or inactive in the game so we come up with the following definitions for a list of words: Related files: --- ILoWord.java In this assignment, we will implement some methods for lists of words. Some of these may be relevant to the later game assignment, others are for practice. All of the following methods should be defined in I Loword. You may need to design helpers for some of the methods as well. Design the method sort that produces a new list, with words sorted in alphabetical order, treating all Strings as if they were given in all lowercase. You may use insertion sort as we did in lecture. Note: The String class defines the method to LowerCase that produces a String just like the one that invoked the method, but with all uppercase letters converted to lowercase. Design the method is Sorted that determines whether this list of Iwords has words sorted in alphabetical order, in a case-insensitive way. Hint: You will likely need a helper method. You may want to review the accumulator style functions we have seen in DrRacket. Design the method interleave that takes this list of IWords and a given list of Iwords, and produces a list where the first, third, fifth... elements are from this list, and the second, fourth, sixth... elements are from the given list. Any "leftover" elements (when one list is longer than the other) should just be left at the end. Design the method merge that merges this sorted list of IWords and a given sorted list of IWords, and produces a sorted list of Iwords that contains all items in both original lists, including duplicates, treating all Strings as if they were given in all lowercase. You should not use sort for this. (This is not the same computation as for interleave, but the two methods are similar. Can you construct an example of two lists such that interleaving them and merging them produce different results? Can you construct another example where the two results are the same?) Design the method checkAndReduce which takes in a string of length 1 and produces an I Loword where any active words in this I LoWord are reduced by removing the first letter only if the given string matches the first letter. Design the method addToEnd that takes in an Iword and produces an ILoWord that is like this I Loword but with the given IWord added at the end. Design the method filterOut Empties that produces an ILoWord with any IWords that have an empty string are filtered out. Design the method draw that takes in a WorldScene and draws all of the words in this ILoWord onto the given WorldScene. Review The Image Library to learn about making a Text Image to display text and the place ImageXY method to place an image on a WorldScene. Choose colors for the background and the words. Active words and inactive words should be different colors. Choose sizes for the background and for the font for words. import tester.Tester; //represents a list of words interface ILoWord { } //represents an empty list of words class MtLoWord implements ILoWord { } class ConsLoWord implements ILoWord { IWord first; ILoWord rest; } ConsLoWord (IWord first, I LoWord rest) { this.first = first; this.rest = rest; //represents a word in the ZType game interface IWord { } } } // represents an active word in the ZType game class ActiveWord implements IWord { String word; } int x; int y; ActiveWord (String word, int x, int y) { this.word= word; this.x = x; this.y = y; } //represents an inactive word in the ZType game class InactiveWord implements IWord { String word; int x; int y; InactiveWord (String word, int x, int y) { this.word = word; } this.x = x; this.y = y; //all examples and tests for ILoWord class ExamplesWordLists { For all questions in this problem, be sure to follow the design recipe carefully: Give sufficient examples of data, and sufficient tests, to test your methods thoroughly. . If you find yourself wanting to use a field-of-field or getters, stop. Fill out the template for each method, and figure out another design. Think carefully about how to use dynamic dispatch, and where to define methods, to keep your code as simple and clean as possible. Note: The following method defined for the class String may be useful: // does this String come before the given String lexicographically? // produce value < 0 if this String comes before that String // produce value zero // produce value > 0 if this String is the same as that String if this String comes after that String int compareTo(String that) In a future assignment, we will be creating a game that deals with lists of words. A word can be active or inactive in the game so we come up with the following definitions for a list of words: Related files: --- ILoWord.java In this assignment, we will implement some methods for lists of words. Some of these may be relevant to the later game assignment, others are for practice. All of the following methods should be defined in I Loword. You may need to design helpers for some of the methods as well. Design the method sort that produces a new list, with words sorted in alphabetical order, treating all Strings as if they were given in all lowercase. You may use insertion sort as we did in lecture. Note: The String class defines the method to LowerCase that produces a String just like the one that invoked the method, but with all uppercase letters converted to lowercase. Design the method is Sorted that determines whether this list of Iwords has words sorted in alphabetical order, in a case-insensitive way. Hint: You will likely need a helper method. You may want to review the accumulator style functions we have seen in DrRacket. Design the method interleave that takes this list of IWords and a given list of Iwords, and produces a list where the first, third, fifth... elements are from this list, and the second, fourth, sixth... elements are from the given list. Any "leftover" elements (when one list is longer than the other) should just be left at the end. Design the method merge that merges this sorted list of IWords and a given sorted list of IWords, and produces a sorted list of Iwords that contains all items in both original lists, including duplicates, treating all Strings as if they were given in all lowercase. You should not use sort for this. (This is not the same computation as for interleave, but the two methods are similar. Can you construct an example of two lists such that interleaving them and merging them produce different results? Can you construct another example where the two results are the same?) Design the method checkAndReduce which takes in a string of length 1 and produces an I Loword where any active words in this I LoWord are reduced by removing the first letter only if the given string matches the first letter. Design the method addToEnd that takes in an Iword and produces an ILoWord that is like this I Loword but with the given IWord added at the end. Design the method filterOut Empties that produces an ILoWord with any IWords that have an empty string are filtered out. Design the method draw that takes in a WorldScene and draws all of the words in this ILoWord onto the given WorldScene. Review The Image Library to learn about making a Text Image to display text and the place ImageXY method to place an image on a WorldScene. Choose colors for the background and the words. Active words and inactive words should be different colors. Choose sizes for the background and for the font for words. import tester.Tester; //represents a list of words interface ILoWord { } //represents an empty list of words class MtLoWord implements ILoWord { } class ConsLoWord implements ILoWord { IWord first; ILoWord rest; } ConsLoWord (IWord first, I LoWord rest) { this.first = first; this.rest = rest; //represents a word in the ZType game interface IWord { } } } // represents an active word in the ZType game class ActiveWord implements IWord { String word; } int x; int y; ActiveWord (String word, int x, int y) { this.word= word; this.x = x; this.y = y; } //represents an inactive word in the ZType game class InactiveWord implements IWord { String word; int x; int y; InactiveWord (String word, int x, int y) { this.word = word; } this.x = x; this.y = y; //all examples and tests for ILoWord class ExamplesWordLists {
Expert Answer:
Related Book For
Posted Date:
Students also viewed these algorithms questions
-
Question (3) A power screw has a major diameter of 20 mm and single square threads with 4 mm pitch. The frictio coefficients are 0.075 for the threads and 0.09 for the collar that has a mean diameter...
-
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...
-
THIRD AVENUE SOFTWARE HEALTH-CARE APP PROJECT This case is new for the ninth edition of Information Technology Project Management . The case provides an opportunity to apply agile and Scrum...
-
a) which ionization gives the best sensitivity the analysis of chloramphenicol? b) The compound with highest retention factor? c) What is the resolution between yohimbine and chloramphenicol? d) What...
-
Use the check register from Exercise 1. It is now one month later, and the checking account statement has arrived. Does the account balance? Checking Account Statement Date Description 12/12 Deposit...
-
The graph of the function f is shown below. The graph of g(x) = - 1/2 f(x) + 1 is which of the following? a. b. c. d. 3-2 y: 54321 5 y: 5432 2345 1 y 5432 5 4. 3211.2.3
-
Prospect Oil Company sold a total of 1,000 Mcf of gas at $9.00/Mcf. The lease provides a 1/5 RI. The working interest owner receives 100% of the revenues (net of 5% severance tax) and then...
-
(a) What specific recommendations would you give the Johnsons for selecting checking and savings accounts that will enable them to effectively use the first and second tools of monetary asset...
-
Mariano is investing in a 401(k) that promises 6.99% annual growth. He plans on investing $150 each month for 32 years (there is no employer matching). Excel calculates an overall account balance of...
-
Assignment Content The more complex a project is, the more things could go wrong. Savvy general managers use a formal process to identify potential problems or risks, implement prevention measures...
-
Prepare journal entries to record the following transactions relating to longterm bonds of Cheyenne Corp. On June 1, 2020, Cheyenne Corp issued $7,520,000, 6 bonds for $7,370,540, which includes...
-
You must show your work to get full credit. Useful formulae: Generalized Kepler's law in general units: P 2 3 a (5) * (M) = (NU) yr AU 1) Solve both forms of Kepler's law for M. Alternative form: 4...
-
The position of a particle moving along a line is given by s(t) = 2+3 - 24t + 90t+7 for t 0. For what values of t is the speed of the particle increasing?
-
To protect the evidence and record interactions with that evidence, criminal investigators establish a chain of evidence, sometimes called a chain of custody. This involves documentation of evidence...
-
Suppose a computer takes 1 nanosecond (=10 second) to execute each operation. Approximately how long will it take the computer to execute the following numbers of operations? Convert your answers...
-
Graph the function F ( x ) = 2 x + 2
-
The amounts of the assets and liabilities of Wilderness Travel Service at April 30, 2019, the end of the year, and its revenue and expenses for the year are listed below. The capital of Harper Borg,...
-
A Firm intends to invest some capital for a period of 15 years; the Firm's Management considers three Options, each consisting of purchasing a machinery of a specific brand, different for each...
-
Left-tailed test; = 0.05 Find the critical z values for the given conditions. In each case assume that the normal distribution applies, so Table A-2 can be used. Also, draw a graph showing the...
-
Test the claim that the sequence of World Series wins by American League and National League teams is random. Given below are recent results with American and National league teams represented by A...
-
Use the given data to find the equation of the regression line. x 2 3 5 5 10 y 6 0 15 5 2
-
Explain revenue management drivers in relation to Kimes and Chases four quadrants model.
-
Within an environment with which you are familiar (hospitality, tourism or events) analyse how revenue management could be applied.
-
Why does revenue maximisation not always lead to profit maximisation?
Study smarter with the SolutionInn App