Loading...
Loading...
Loading...
A phone creates its own battery and never hands it out. The battery level stays between 0 and 100, and the battery itself enforces that rule.
Write Battery (a private level, use(int p), charge(int p), getLevel()) and Phone, which creates its Battery inside its constructor from the starting level and forwards use and charge to it.
use p or charge p.MODEL: L%, followed by (low) when L is below 15.Example
Input
Redmi 50 4 use 30 use 10 charge 70 use 120
Output
Redmi: 20% Redmi: 10% (low) Redmi: 80% Redmi: 0% (low)
50 − 30 = 20, then 10 (low), then 80, then it cannot go below 0.
Try the problem first. Open one hint at a time.
The clamping belongs in Battery, not in Phone or main.
Phone keeps private Battery battery; and builds it with new Battery(level) in its constructor.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor