Your friend Johannes loves doing DIY (do it yourself) hardware. They just built a juice-maker, Johannes is very excited about it. Johannes's goal is to be able to make fresh juice every morning.
Johannes Juice maker has a lot of fancy features. Like a built-in measurement system, which can tell you how much juice is in the cup. It also has a timer, telling you how long the machine has been running.
Johannes isn't the best at programming, but they want to make a program to control the machine. They have thereby asked you to help them.
The machine has a debug light, it is a simple mechanic, if the machine has power the debug light is on. The program will only run if the debug light is on.
This method should be a class method called JuiceMaker.
Define the class method JuiceMaker.debug_light_on? that returns true.
JuiceMaker.debug_light_on?
#=> trueWhen the machine is powered on it should create an instance of a class called JuiceMaker.
The machine is supposed to have an initialized state.
The initialized state should hold the following information:
false when the machine is turned on.Define the initialized state, which takes the amount of juice in the cup as a parameter, and construct the initialized state.
The initialized state should host an instance variable @running that is set to false, and an instance variable @fluid that is based on an argument given when the class is initialized.
JuiceMaker.new(5)
#=> #<JuiceMaker:0x10f0b8 @running=false, @fluid=5>The machine can be turned on and off.
You need to define a method to turn on the machine.
When the machine is turned on, the running state should be set to true.
Define the method JuiceMaker#start that turns the machine on.
juice_maker = JuiceMaker.new(5)
juice_maker.start
juice_maker
#=> #<JuiceMaker:0x10f0b8 @running=true, @fluid=5>The machine needs to be able to tell you the status of the machine.
It should return true if the machine is running, and false if the machine is not running.
Define the method JuiceMaker#running? that returns the machine's status.
juice_maker = JuiceMaker.new(5)
juice_maker.start
juice_maker.running?
#=> trueThe machine can add juice to the cup. The machine can tell how much juice is added to the cup. The machine needs help to know how much juice is in the cup after the juice is added.
Define the method JuiceMaker#add_fluid, which takes the amount of juice added as a parameter and updates the amount of juice in the cup.
juice_maker = JuiceMaker.new(5)
juice_maker.add_fluid(5)
juice_maker
#=> #<JuiceMaker:0x10f0b8 @running=false, @fluid=10>The machine can be turned on and off.
You need to define a method to turn off the machine
This method will only be called when the machine is running.
When the machine is turned off, the running state should be set to false.
The machine also needs help determining how much juice is in the cup after it is turned off.
The machine uses five units of juice per minute.
Define the method JuiceMaker#stop that takes the number of minutes the machine has been running as a parameter and returns the amount of juice in the cup after the machine has been turned off.
juice_maker = JuiceMaker.new(5)
juice_maker.start
juice_maker
#=> <JuiceMaker:0x10f0b8 @running=true, @fluid=5>
juice_maker.stop(1)
#=> #<JuiceMaker:0x10f0b8 @running=false, @fluid=0>Your friend Johannes loves doing DIY (do it yourself) hardware. They just built a juice-maker, Johannes is very excited about it. Johannes's goal is to be able to make fresh juice every morning.
Johannes Juice maker has a lot of fancy features. Like a built-in measurement system, which can tell you how much juice is in the cup. It also has a timer, telling you how long the machine has been running.
Johannes isn't the best at programming, but they want to make a program to control the machine. They have thereby asked you to help them.
The machine has a debug light, it is a simple mechanic, if the machine has power the debug light is on. The program will only run if the debug light is on.
This method should be a class method called JuiceMaker.
Define the class method JuiceMaker.debug_light_on? that returns true.
JuiceMaker.debug_light_on?
#=> trueWhen the machine is powered on it should create an instance of a class called JuiceMaker.
The machine is supposed to have an initialized state.
The initialized state should hold the following information:
false when the machine is turned on.Define the initialized state, which takes the amount of juice in the cup as a parameter, and construct the initialized state.
The initialized state should host an instance variable @running that is set to false, and an instance variable @fluid that is based on an argument given when the class is initialized.
JuiceMaker.new(5)
#=> #<JuiceMaker:0x10f0b8 @running=false, @fluid=5>The machine can be turned on and off.
You need to define a method to turn on the machine.
When the machine is turned on, the running state should be set to true.
Define the method JuiceMaker#start that turns the machine on.
juice_maker = JuiceMaker.new(5)
juice_maker.start
juice_maker
#=> #<JuiceMaker:0x10f0b8 @running=true, @fluid=5>The machine needs to be able to tell you the status of the machine.
It should return true if the machine is running, and false if the machine is not running.
Define the method JuiceMaker#running? that returns the machine's status.
juice_maker = JuiceMaker.new(5)
juice_maker.start
juice_maker.running?
#=> trueThe machine can add juice to the cup. The machine can tell how much juice is added to the cup. The machine needs help to know how much juice is in the cup after the juice is added.
Define the method JuiceMaker#add_fluid, which takes the amount of juice added as a parameter and updates the amount of juice in the cup.
juice_maker = JuiceMaker.new(5)
juice_maker.add_fluid(5)
juice_maker
#=> #<JuiceMaker:0x10f0b8 @running=false, @fluid=10>The machine can be turned on and off.
You need to define a method to turn off the machine
This method will only be called when the machine is running.
When the machine is turned off, the running state should be set to false.
The machine also needs help determining how much juice is in the cup after it is turned off.
The machine uses five units of juice per minute.
Define the method JuiceMaker#stop that takes the number of minutes the machine has been running as a parameter and returns the amount of juice in the cup after the machine has been turned off.
juice_maker = JuiceMaker.new(5)
juice_maker.start
juice_maker
#=> <JuiceMaker:0x10f0b8 @running=true, @fluid=5>
juice_maker.stop(1)
#=> #<JuiceMaker:0x10f0b8 @running=false, @fluid=0>