Skip to content

Instantly share code, notes, and snippets.

Created December 15, 2017 23:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/3856b0dd6f37adf125f7aefd781f14ac to your computer and use it in GitHub Desktop.
Save anonymous/3856b0dd6f37adf125f7aefd781f14ac to your computer and use it in GitHub Desktop.
public class lightbulb {
// light level is 0 to 10 where 0 is off and 10 is full brightness
private int dimmerLevel;
public lightbulb() {
dimmerLevel = 0; // initialize the light as "off"
}
// set the light bulb brightness to a new level
public setDimmer(int dimmerLevel) {
if (dimmerLevel >= 0 && dimmerLevel <= 10) {
this.dimmerLevel = dimmerLevel;
} else {
throw new IllegalArgumentException("Invalid dimmer level!");
}
}
// get how bright the light is
public getBrightness() {
return dimmerLevel;
}
// check if the light is on
public isOn() {
if (dimmerLevel > 0) {
return true;
} else {
return false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment