Answered step by step
Verified Expert Solution
Question
1 Approved Answer
State Pattern - A Lamp has three states that it rotates through when a button is pressed: OFF BRIGHT DIM. The Lamp starts in the
State Pattern A Lamp has three states that it rotates through when a button is pressed: OFF BRIGHT DIM. The Lamp starts in the OFF state. Complete the UML by drawing the missing Lamp class with its methods and all connections. Then complete the code. In the main, construct a lamp and switch it to the BRIGHT state.
tableOffStatebuttonpressself lamp
tableBrightStatebuttonpressself lamp
tableDimStatebuttonpressself lamp
import abc
class LampState :
pass
import lampstate
import brightstate
class OffStat def buttonpressself lamp:
return "OFF BRIGHT"
import class Lamp:
def self:
def changestateself state:
def pushbuttonself:
import lamp
def main:
lamp print
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started