Question: Previously, your Scene class used an array to store its Marks. Now you are going to refactor your code to use a different data structure.

Previously, your Scene class used an array to store its Marks. Now you are going to refactor your code to use a different data structure. Refactor means to rewrite parts of the code to improve it. To refactor is not to change what the program can do. That is, when you refactor, you are changing the implementation (how) but not the specification (what). The class we want you to use is Javas built-in ArrayList. To use one, do the following: // at the top of the file that uses ArrayList import java.util.List; import java.util.ArrayList; // how to declare a List reference; // example: a list containing Integers. // Youll need to replace Integer with the type of object you are actually // storing in the List List x; // how to allocate a new ArrayList x = new ArrayList<>(); To find out what methods you can call on a List, see the Method Summary section of the documentation of List. Below, we repeat the HW2 description of the Scene class, except you will see the callout REFACTOR whenever there are changes to the original implementation requirements. The Scene class represents ordered collection of Marks. It coordinates the drawing of multiple Marks onto a ColorGrid. The collection of Marks is ordered because the Marks can to be drawn one at a time. For a given coordinate on the ColorGrid, the last Mark wins! That means earlier Marks will be painted over by later Marks if there is an overlap.

Here are your tasks. 6.1. Be able to draw the background To do this, you need to complete the following in Scene.java. constructor Add enough instance variables to Scene just for what you need right now o Hint: you do not need maxMarks yet draw method o should make all the ColorGrids pixels to be whatever the background color was that was passed to the constructor

import bridges.base.ColorGrid; import bridges.base.Color; public class Scene { private int maxmarks; private Color backgroundcolor; private Mark[] mark; private ColorGrid colorgrind; private int marknums; /* Creates a Scene with a maximum capacity of Marks and with a background color. maxMarks: the maximum capacity of Marks backgroundColor: the background color of this Scene */ public Scene(int maxMarks, Color backgroundColor) { maxmarks = maxMarks; backgroundcolor =backgroundColor; mark = new Mark[maxmarks]; marknums =0; } // returns true if the Scene has no room for additional Marks private boolean isFull() { if(marknums == maxmarks){ return true; } return false; } /* Adds a Mark to this Scene. When drawn, the Mark will appear on top of the background and previously added Marks m: the Mark to add */ public void addMark(Mark m) { if (isFull()) throw new IllegalStateException("No room to add more Marks"); mark[marknums] = m; marknums ++; } /* Helper method: deletes the Mark at an index. If no Marks have been previously deleted, the method deletes the ith Mark that was added (0 based). i: the index */ protected void deleteMark(int i) { for (int x=i; x                                             

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!