Question: Question: in a package named oop.electronics, implement the following. This functionality is the same as the last lecture question, but we will use inheritance to

Question: in a package named "oop.electronics", implement the following. This functionality is the same as the last lecture question, but we will use inheritance to prevent duplicating code. class Battery with A constructor that takes a variable named "charge" of type Int abstract class Electronic with A constructor that takes no parameters A state variable named "battery" of type Battery A method named "use" that takes no parameters and returns Unit (This can be abstract) 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 Electronic's state variable The returned Battery is the one that was in the state variable when the method is called class BoomBox that extends Electronic A constructor that takes a variable of type Battery and assigned it to the inherited state variable named "battery" Your constructor parameter should have a different name than the state variable Override the "use" method to reduce the charge of the battery in the state variable by 3 if its charge is 3 or greater class FlashLight that extends Electronic A constructor that takes no parameters When a new FlashLight is created, assign the inherited state variable named "battery" to a new Battery with 5 charge (ie. Batteries included) Override the "use" method to reduce the charge of the battery in the state variable by 1 if its charge is 1 or greater

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!