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
-
Describe the concept of "money as a weapon" and the associated authorities, factors, and decision methodology involved in enhancing force capability. Provide an example(s) or scenario(s) depicting...
-
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...
-
Toby's Trucking Company determined that the distance traveled per truck per year is normally distributed, with a mean of 50 thousand miles and a standard deviation of 12 thousand miles. a. What...
-
Suppose that Chevrolet used target costing to decide whether to produce a new vehicle, such as the Chevrolet Spark. Required: A. Describe the steps Chevrolets design team would have taken. B. Explain...
-
The percentage of credit sales approach is closely related to the: a. statement of financial position. b. statement of retained earnings. c. statement of cash flows. d. statement of earnings.
-
Had the dealer engaged in deceptive advertising? Why or why not? Leota Sage saw a local motorcycle dealers newspaper advertisement for a MetroRider EZ electric scooter for $1,699. When she went to...
-
Scott earns a salary of $7.90 per hour at the video rentalstore scott has to work overtime (time more than 45 hours but less than 60 hours. For hall Scott's salary is given by the function SO 355.6 4...
-
Considering the following information Sale price Variable cost per unit Fixed costs Number of units to sell Amount $30 $10 $8,000 per month 1,200 per month What is the contribution margin rate?...
-
On December 31, 2020, Patty Corp. subjected to impairment test a building which was the company's factory site. Because of the expected decline the demand for the company's product, the company...
-
11. Chaoprava Av is an investment advisor for high-net-worth individuals. One of her clients, Schuylkill Cy, plans to contribute four level annual payments of $76,500 starting in 10 years. Av...
-
A laptop has a listed price of $895.95 before tax,If the sales rate is 7.75% find the total cost cost with sales cost included. Andrew bought tacos and left 25% tip at $2 What was the price of the...
-
How do maternal-fetal interactions during pregnancy, including placental development, nutrient transport, and immune tolerance, support embryonic growth and development, and what are the implications...
-
Who are the typical stakeholders who contribute to the menu-planning process in a new business? Who is normally added to the process in an existing business?
-
Question Completion Status: Preferred shares, $12 cumulative, 200,000 shares authorized, 90,000 shares issued & outstanding Common shares, 500,000 shares authorized, 200,000 shares issued &...
-
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...
-
Find a Hamilton path from vertex \(s\) to vertex \(v\) for each graph in Figure 12.179 or indicate that there is none. W W Graph A Graph B V W Graph C Graph D Figure 12.179 Graphs A, B, C, and D
-
Use Figure 12.185 to determine if the given sequence of vertices is a Hamilton path, an Euler trail, both, or neither. 1. Graph \(A, e ightarrow b ightarrow a ightarrow e ightarrow d ightarrow c...
-
Suppose you have a complete weighted graph with vertices \(N, M, O\), and \(P\). 1. Use the formula \((n-1)\) ! to calculate the number of distinct Hamilton cycles in the graph. 2. Use the formula...
Study smarter with the SolutionInn App