Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For all questions in this problem, be sure to follow the design recipe carefully: Give sufficient examples of data, and sufficient tests, to test

 

imageimage

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 {

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Elementary Statistics

Authors: Mario F. Triola

3rd Canadian Edition

032122597X, 978-0321225979

More Books

Students also viewed these Algorithms questions