Question: We have written the following Pixel interface: interface Pixel { public int getIntensity(); public void setIntensity(int x); } TASK: Create a class called GrayscalePixel that

We have written the following Pixel interface:

interface Pixel { public int getIntensity(); public void setIntensity(int x); }

TASK: Create a class called GrayscalePixel that has the following properties:

  • It must implement the Pixel interface
  • It must have a public final static variable of type int called MIN_INTENSITY that is 0
  • It must have a public final static variable of type int called MAX_INTENSITY that is 255
  • It should have a private instance variable of type int called intensity
  • It must have a constructor that has one parameter of type int, and it should set the intensity instance variable to the constructor argument. If the constructor argument is less than MIN_INTENSITY, the intensity instance variable should be set to MIN_INTENSITY. If the constructor argument is greater than MAX_INTENSITY, the intensity instance variable should be set to MAX_INTENSITY
  • The getIntensity instance method should return the intensity instance variable
  • The setIntensity instance method should replace the intensity instance variable with the method argument. If the method argument is less than MIN_INTENSITY, the intensity instance variable should be set to MIN_INTENSITY. If the method argument is greater than MAX_INTENSITY, the intensity instance variable should be set to MAX_INTENSITY

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!