This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: 15-100 PROGRAM 9 - FALL 2007Due: Monday, November 19 by 11:59PM using electronic hand-in BACKGROUND Using the same toy store from Program 8, you will write new methods for the ToyStoreclass to help maintain the collection of toy bins. Download a new copy of the zip file to use.The ToyBinclass is as given in Program 8 along with a simple toStringmethod. The ToyStoreclass has been revised so that the size of the binArraycan increase as more bins are added. Specifically, the size of the array starts at 1 as we did in lecture, and there is a doubleLengthmethod that you should call onlyif you are going to insert a new toy bin into the array and the array is full. You will write three methods for the ToyStoreclass. Each method has its own tester class. Read each tester class carefully to see what conditions it is testing for your method. Then use the sample output at the end of this assignment to compare your results with ours. DO NOT CHANGE ANY CODE THAT IS ALREADY GIVEN TO YOU. ASSIGNMENT 1. Complete the insertmethod for the ToyStoreclass that has a parameter that references a ToyBinwith at least one toy in it. This method should insert the toy bin into the array of toy bins so that all the toy bins are in alphabetical order based on the toy names. You may assume that the toy bins that are already in the array are in alphabetical order already. If the insert method tries to insert a toy bin that has the same toy as another bin, just add the toys in the new bin into the bin that is already in the array. To order strings containing only letters based on alphabetical order, you need to use the compareTomethod in the Stringclass. This method has the following signature: public int compareTo(String otherString) This method returns a negative integer if this string comes before the other string alphabetically, a positive integer if this string comes after the other string alphabetically, or 0 if this string is identical to the other string. So for example, if word1and word2are two strings holding only uppercase letters, then we can print them out in alphabetical order by writing: if (word1.compareTo(word2) < 0)System.out.println(word1 + " " + word2); else if (word1.compareTo(word2) > 0) System.out.println(word2 + " " + word1); else System.out.println("These are the exact same words."); 2. Write a removemethod for the ToyStoreclass that has an intparameter representing a specific bin position. If there is a toy bin at this bin position in the toy store, remove this toy bin, shifting the subsequent toy bins one position to fill in the gap left by the removed toy bin. If not, output the error message "INVALID BIN POSITION" and do not change the toy store. The valid bin positions are numbered from to numBins-1....
View Full Document
- Fall '07
- Hasbro, Easy-Bake Oven, binArray