Implement a static java method called calculateScore that takes in a two dimensional array of colors and a target color

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Implement a static java method called calculateScore that takes in a two dimensional array of colors and a target color

Post by answerhappygod »

Implement a static java method called calculateScore that takesin a two dimensional array of colors and a target color asarguments, and will return the calculated score of the array. Use the pixel class defined here:
Implement A Static Java Method Called Calculatescore That Takes In A Two Dimensional Array Of Colors And A Target Color 1
Implement A Static Java Method Called Calculatescore That Takes In A Two Dimensional Array Of Colors And A Target Color 1 (328.03 KiB) Viewed 47 times
RULES:
The only cells that are to be considered for this calculationare the cells along the border. If a cell along the border has thetarget color, add 1 point to the points of the color. If a cellalong the border has the target color and is also in the corner,add 2 points to the points of the color. It a cell along theborder does not have the target color, add 0 points to thepoints of the color. The grid score is the sum of the points of theborder cells.
EX:
Implement A Static Java Method Called Calculatescore That Takes In A Two Dimensional Array Of Colors And A Target Color 2
Implement A Static Java Method Called Calculatescore That Takes In A Two Dimensional Array Of Colors And A Target Color 2 (218.49 KiB) Viewed 47 times
public class Pixel { /** * The (@code Pixel) representing the RGB color black. */ public static final Pixel BLACK = new Pixel (0, 0, 0); /** * The (@code Pixel) representing the RGB color blue. */ public static final Pixel BLUE = new Pixel (0, 0, 255); /** * The (@code Pixel} representing the RGB color red. */ public static final Pixel RED = new Pixel (255, 0, 0); /** * The (@code Pixel} representing the RGB color green. */ public static final Pixel GREEN = new Pixel (0, 255, 0); / * * * The (@code Pixel} representing the RGB color white. */ public static final Pixel WHITE = new Pixel (255, 255, 255); /** * The (@code Pixel} representing the RGB color yellow. */ public static final Pixel YELLOW = new Pixel (255, 255, 0); private final int[] component; /** * Create a new pixel with the provided color components. * @param r the red component of the pixel * @param g the green component of the pixel * @param b the blue component of the pixel */ public Pixel (int r, int g, int b) { component = new int [3]; component [0] = r; component [1] =g; component [2] = b; }
Blue Green White Green Red Red Black Yellow Black Blue Black Red computeScore (grid, Pixel.BLUE) returns 3 (corner cell (0,0) and cell (2,1)) computeScore (grid, Pixel.RED) returns 5 (2 corner cells (2,0) and (2,2) and cell (1,0)) computeScore (grid, Pixel. YELLOW) returns 0 (no perimeter cell with YELLOW) computeScore (grid, Pixel.BLACK) returns 2.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply