Build the ShapeWindow Class Make your new ShapeWindow class by right-clicking on the package project1 and...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Build the ShapeWindow Class Make your new ShapeWindow class by right-clicking on the package "project1" and then selecting New → Class. Name it ShapeWindow and select the "Generate comments" checkbox. Copy import statements The classes you write will require the following code. Copy and paste them after the package statement at the top of your class file. import bag.Bag; import bag. BagInterface; import cs2. TextShape; import java.util.Random; import cs2.Window; import cs2.Button; import cs2.WindowSide; This will give you access to all the classes you will need to implement the ShapeWindow class. Fill out the fields and methods to match the class diagram - don't worry about implementing them yet. <<Java Class>> ShapeWindow project1 window: Window textShape: TextShape quitButton: Button chooseButton: Button itemBag: BagInterface<String> ShapeWindow(BagInterface<String>) ⚫ clicked Quit(Button):void → clickedChoose (Button):void colorText():void centerText():void Implement ShapeWindow's constructor Initialize the window field inside the ShapeWindow constructor. To do this, call the default constructor of the Window class. Set the title of window to "Project 1", using it's setTitle(String title) method. Initialize the itemBag field to point to your constructor's parameter. Don't worry about initializing the remaining fields yet. We will get to that later! Build the DisplayCollection Class Create the Display Collection class the same way you created the ShapeWindow class. Fill out the fields and methods to match the class diagram. <<Java Class>> DisplayCollection project1 SF STRINGS: String[] itemBag: BagInterface<String> DisplayCollection() ⚫ getitemBag():BagInterface<String> The STRINGS constant We want the STRINGS field to be a constant that is available to any other class. To be able to do that, we have to do three things: First, we have to make the field public, so that anyone can access the field. Second, to avoid having to create a new instance of the Display Collection class every time we want to access the STRINGS constant, we need to make the field "belong" to the Display Collection class itself. To do that, we have to add the keyword static in front of the field. (You can do the same to any method for the same effect!) Third, in order to prevent anyone from changing the content of the STRINGS constant, we have to add the final keyword in front of the field as well. The final keyword means that the variable can only be initialized once. This also means that we have to initialize the field immediately! Initialize the STRINGS field to be an array that contains all of the possible strings in the bag. The strings can be: "red circle", "blue circle", "red square”, and "blue square". Note: When accessing the STRINGS constant, you need to write Display Collection.STRINGS. Implement Display Collection's constructor Initialize the itemBag field by using the default constructor of the Bag class. Since the Bag class is a "generic" class, you will have to use the "diamond operator": this.itemBag = new Bag<>(); Implement the getItemBag method Make getItemBag() return the itemBag field. Build the ShapeWindow Class Make your new ShapeWindow class by right-clicking on the package "project1" and then selecting New → Class. Name it ShapeWindow and select the "Generate comments" checkbox. Copy import statements The classes you write will require the following code. Copy and paste them after the package statement at the top of your class file. import bag.Bag; import bag. BagInterface; import cs2. TextShape; import java.util.Random; import cs2.Window; import cs2.Button; import cs2.WindowSide; This will give you access to all the classes you will need to implement the ShapeWindow class. Fill out the fields and methods to match the class diagram - don't worry about implementing them yet. <<Java Class>> ShapeWindow project1 window: Window textShape: TextShape quitButton: Button chooseButton: Button itemBag: BagInterface<String> ShapeWindow(BagInterface<String>) ⚫ clicked Quit(Button):void → clickedChoose (Button):void colorText():void centerText():void Implement ShapeWindow's constructor Initialize the window field inside the ShapeWindow constructor. To do this, call the default constructor of the Window class. Set the title of window to "Project 1", using it's setTitle(String title) method. Initialize the itemBag field to point to your constructor's parameter. Don't worry about initializing the remaining fields yet. We will get to that later! Build the DisplayCollection Class Create the Display Collection class the same way you created the ShapeWindow class. Fill out the fields and methods to match the class diagram. <<Java Class>> DisplayCollection project1 SF STRINGS: String[] itemBag: BagInterface<String> DisplayCollection() ⚫ getitemBag():BagInterface<String> The STRINGS constant We want the STRINGS field to be a constant that is available to any other class. To be able to do that, we have to do three things: First, we have to make the field public, so that anyone can access the field. Second, to avoid having to create a new instance of the Display Collection class every time we want to access the STRINGS constant, we need to make the field "belong" to the Display Collection class itself. To do that, we have to add the keyword static in front of the field. (You can do the same to any method for the same effect!) Third, in order to prevent anyone from changing the content of the STRINGS constant, we have to add the final keyword in front of the field as well. The final keyword means that the variable can only be initialized once. This also means that we have to initialize the field immediately! Initialize the STRINGS field to be an array that contains all of the possible strings in the bag. The strings can be: "red circle", "blue circle", "red square”, and "blue square". Note: When accessing the STRINGS constant, you need to write Display Collection.STRINGS. Implement Display Collection's constructor Initialize the itemBag field by using the default constructor of the Bag class. Since the Bag class is a "generic" class, you will have to use the "diamond operator": this.itemBag = new Bag<>(); Implement the getItemBag method Make getItemBag() return the itemBag field.
Expert Answer:
Related Book For
Intermediate Accounting
ISBN: 978-1260481952
10th edition
Authors: J. David Spiceland, James Sepe, Mark Nelson, Wayne Thomas
Posted Date:
Students also viewed these programming questions
-
123 Compare the purely graphical properties of these two notations, and the ways in which the graphical properties of each display correspond to the information structure being defined. Describe...
-
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.
-
The Kc for the following reaction is 9.30 X 10^-2 at 25C:PCl5(g) <-> PCl3(g) + Cl2(g) How many moles & grams of PCl5 must be added to a 2-literflask to obtain a Cl2 concentration of 0.150M...
-
Saphire, Inc., bottles and distributes mineral water from the company's natural springs in northern Oregon. Saphire markets two products: 12-ounce disposable plastic bottles and 1-gallon reusable...
-
Consider the air-standard Otto cycle described in Problem 9.94 operating with a compression ratio of 8 (= V max /V min ). The air just prior to compression is at 293 K and 1 atm. The maximum cycle...
-
Plaintiff purchased stain and paint from defendant that, upon application, presented significant issues: discoloration and cracking. These issues became apparent 30 days after receipt of the...
-
Chandler Hats Corporation manufactures three different models of hats: Vogue, Beauty, and Glamour. Chandler expects to incur $360,000 of overhead cost during the next fiscal year. Other budget...
-
1. there are two different schools of thought on how to lower gasoline prices and reduce U.S. dependence on foreign oil. One is to increase supply of oil (drilling offshore), and the other is to...
-
Jeffrey Helm owns a health and fitness center called Bulk- Up in Harrisburg. He is considering adding more floor space to meet increasing demand. He will either add no floor space ( N), a moderate...
-
Calculate the Fitts index of difficulty for the following sport tasks: throwing a strike in baseball. scoring a basket from the free-throw line, successfully scoring a field goal from 35 yd in...
-
Shi Import-Export's balance sheet shows $400 million in debt, $60 million in preferred stock, and $260 million in total common equity. Shi's tax rate is 15%, rd = 9%, rps = 8.9%, and rs = 13%. If Shi...
-
A firm has sales of $1.3 million, and 15 percent of the sales are for cash. The year-end accounts receivable balance is $150,000. What is the average collection period? (Use a 360-day year. Do not...
-
If the 1-year rate of return is 20% and the interest rates are constant, what is the 5-year holding rate of return? Q 2-11 If you invest $2,000 today and it earns 25% per year, how much will you have...
-
Village Finance Co . advanced three loans to Kamiko $ 3 , 1 0 0 on June 9 , $ 2 , 7 0 0 on August 1 4 , and $ 2 , 2 0 0 on October 1 8 . Simple interest at 7 . 7 0 % was charged on all three loans,...
-
A company has issued preferred stock with an annual dividend of $2.42 that will be paid in perpetuity. The current price of the stock is $24.6. What is the expected rate of return on the preferred...
-
3. Answer the following questions for the following circuit. R1 = R11 = R12 = 5 k2 w R1 all others are 10 ko. R2 R3 12V R5 R6 R7 R4 R10 R8 R12 R9 R11 a) Reduce the circuit as far as possible using...
-
On March 31, 2018, Gardner Corporation received authorization to issue $30,000 of 9 percent, 30-year bonds payable. The bonds pay interest on March 31 and September 30. The entire issue was dated...
-
EDGAR, the Electronic Data Gathering, Analysis, and Retrieval system, performs automated collection, validation, indexing, and forwarding of submissions by companies and others who are required by...
-
What is comprehensive income? How does comprehensive income differ from net income? Where do companies report it in a balance sheet?
-
At January 1, 2021, NCI Industries, Inc. was indebted to First Federal Bank under a $240,000, 10% unsecured note. The note was signed January 1, 2014, and was due December 31, 2022. Annual interest...
-
What were Aristotles two main classifications of motion?
-
One kg weighs 10 N on Earth. Would it weigh more or less on the Moon?
-
Which has the greater density1 kg of water or 10 kg of water?
Study smarter with the SolutionInn App