Question: [SCALA] Write a program with: class Battery with A constructor that takes a variable named charge of type Int . class BoomBox with A constructor
[SCALA]
Write a program with:
![[SCALA] Write a program with: class Battery with A constructor that takes](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f2e81cdeac5_16466f2e81c74ace.jpg)
class Battery with A constructor that takes a variable named "charge" of type Int . class BoomBox with A constructor that takes a variable named "battery" of type Battery A method named "use" that takes no parameters and returns Unit This method will decrease the charge of the BoomBox's battery by 3 If the charge of the battery is less than three, this method does nothing A method named "replaceBattery" that takes a Battery as a parameter and returns a Battery This method swaps the input Battery with the Battery currently stored in this BoomBox's state variable The returned Battery is the one that was in the state variable when the method is called class Battery with A constructor that takes a variable named "charge" of type Int . class BoomBox with A constructor that takes a variable named "battery" of type Battery A method named "use" that takes no parameters and returns Unit This method will decrease the charge of the BoomBox's battery by 3 If the charge of the battery is less than three, this method does nothing A method named "replaceBattery" that takes a Battery as a parameter and returns a Battery This method swaps the input Battery with the Battery currently stored in this BoomBox's state variable The returned Battery is the one that was in the state variable when the method is called
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
