Question: Please do 2 and 3. Part 2: Add a LineWidthOp class, and integrate into simulation Add a new capability to change line widths. 1. Add
Please do 2 and 3.



Part 2: Add a LineWidthOp class, and integrate into simulation Add a new capability to change line widths. 1. Add a new class to the package called LineWidthOp. To do this, right-click on the ColorOp.java class and select Refactor->Copy.. In the dialog box that comes up, rename the copy to LineWidthOp' then click Refactor. Copy Class New Name: LineWidthop Project: OperationUndo Location: Source Packages To Package: operationundo Preview Refactor Cancel Help 2. In the new class' code, replace the String colName property with an int lineWidth property. Change the constructor and the toString method to reflect this. 3. In the simulation, modify the createNewOp method so that there are three more switch cases for lineWidths of 1, 2,5. Make sure to change the number in the first statement of the method so that these new ops have a chance to be created. 4. Run the simulation and make sure that you are seeing shape drawing, color changes and line width changes. When you are finished, submit LineWidthOp.java to Canvas. What is important to notice here is that the stack in the simulation can hold DrawingOp objects, but it can also hold ColorOp objects and LineWidthOp objects, because these both inherit from (i.e., are subclasses of) DrawingOp. Remember that an object reference variable can refer to a class or to any of its subclasses. */ package operationundo; /** * @author clatulip */ public class LineWidthOp extends DrawingOp { private String colName; public LineWidthop(String name, String colName) { super(name); this.colName = colName; } @Override public String toString() { return super.toString() + } 11 StateOp{" + "colName=" + colName + '}'; } Part 2: Add a LineWidthOp class, and integrate into simulation Add a new capability to change line widths. 1. Add a new class to the package called LineWidthOp. To do this, right-click on the ColorOp.java class and select Refactor->Copy.. In the dialog box that comes up, rename the copy to LineWidthOp' then click Refactor. Copy Class New Name: LineWidthop Project: OperationUndo Location: Source Packages To Package: operationundo Preview Refactor Cancel Help 2. In the new class' code, replace the String colName property with an int lineWidth property. Change the constructor and the toString method to reflect this. 3. In the simulation, modify the createNewOp method so that there are three more switch cases for lineWidths of 1, 2,5. Make sure to change the number in the first statement of the method so that these new ops have a chance to be created. 4. Run the simulation and make sure that you are seeing shape drawing, color changes and line width changes. When you are finished, submit LineWidthOp.java to Canvas. What is important to notice here is that the stack in the simulation can hold DrawingOp objects, but it can also hold ColorOp objects and LineWidthOp objects, because these both inherit from (i.e., are subclasses of) DrawingOp. Remember that an object reference variable can refer to a class or to any of its subclasses. */ package operationundo; /** * @author clatulip */ public class LineWidthOp extends DrawingOp { private String colName; public LineWidthop(String name, String colName) { super(name); this.colName = colName; } @Override public String toString() { return super.toString() + } 11 StateOp{" + "colName=" + colName + '}'; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
