Created
December 15, 2017 23:28
-
-
Save anonymous/3856b0dd6f37adf125f7aefd781f14ac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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