Hash Sets Every pixel on your computer’s screen has a unique position described by a pair ( x, y ), such that x and y are positive integers. The x -coordinate of a pixel, p, is the number of pixels...


Hash Sets


Every pixel on your computer’s screen has a unique position described by a pair ( x, y ), such that x and y are positive integers. The x -coordinate of a pixel, p, is the number of pixels from the left edge of the screen to p ; the y -coordinate of p is the number of pixels from the top of the screen to p . Thus, the position of the pixel at the top left corner of your screen is (0, 0). Write a Position class with integer fi elds x and y that represent the screen position of a pixel. Override equals(Object o) . The implementation of a video game must determine whether or not a given position is lit. When the game starts, no position is lit. A hash table is used to keep track of which positions are lit. Write a program that generates a list of 5000 random positions ( x ranges from 0 to 60, and y ranges from 0 to 40). If the position is unlit, (not in the hash table) add it to the hash table (i.e., light it), and if it is lit, then remove it from the table (“unlight” it). Remember to override hashCode() . When your program concludes, print a picture using ‘*’s and blanks that simulates the lit and unlit pixels. Display the number of pixels that are lit.

Nov 17, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here