Write a static method called adjustTV that that takes as a
parameter a Scanner containing a series of tokens that represent
adjustment to a TV. There are two types of commands: "power" which
turns the TV on or off, and "volume" followed by a whole number,
which adjusts the volume up or down by that amount. By default the
TV is off and at volume 0. Volume adjustments can only happen when
the TV is on. If a volume adjustment will make the volume lower
than 0, the volume should be set at 0, and if the volume will be
set over 10, it should be just set to 10. At the end of the method,
it should print out whether the TV is "on" or "off" at the end
along with the final volume. For example, if a Scanner called
"changes" contained the following tokens:
and we made the following call:
the method should print out:
This is because the TV starts turned off, and the first "power"
turns the the TV on. The volume is increased by 3, so the volume is
3, then it is decresed by 5 which would make it negative, so it is
set to 0, then it is increased by 7, making it 7. The TV is turned
back off and the last volume adjustment does nothing. You may not
construct any extra data structures to solve this problem.
If you could give a breakdown of your thought process that would
be great!
Write a static method called adjustTV that that takes as a parameter a Scanner containing a series of tokens that repres
-
- Posts: 43759
- Joined: Sat Aug 07, 2021 7:38 am