Question
Greenfoot project in java for exercise 10.49, you need to display the volume either in a vertical bar or a horizontal bar. This volume bar
Greenfoot project in java
for exercise 10.49, you need to display the volume either in a vertical bar or a horizontal bar. This volume bar is for display volume only, and nothing should happen if you click on the bar, because it is not supposed to respond to user clicking on the bar. The lowest value is 0, and the highest value is 100.According to class GreenfootSound , its method getVolume() indicates that the volume is between 0 and 100.Alone with the bar, you also need to display the current volume level in numeric value, such as number 97 in the picture below.
the step for increasing and decreasing volume should be set to 2 or 5. The initial volume level should be set to 50, which is right in the middle of the volume.
the efficiency of your solution is very important. When the program runs, the initial volume should be set to 50, with corresponding volume bar and volume number displayed.After that, an efficient solution will update the volume display bar and change the volume of the song, only when user has clicked the up or down volume button. Therefore, if you solution keep re-drawing the volume bar, or keep re-displaying the volume number, or keep re-setting the volume level of the song, even when user has not clicked on any button, then that is not an efficient solution, and you should avoid providing such an inefficient solution.
the solutions of these four exercises need to co-exist in one scenario, and you don't need to comment out any finished exercise when you are debugging the next exercise.
zip the entire scenario folder "johndoe-mp3", and rename the zip file as "JohnDoeHw10.zip", where JohnDoe needs to be replaced by your first and last name
submit the zip file JohnDoeHw10.zip to Moodle "homework 10 drop box".
Additional requirement:
there should be no static data used in any of the classes in your homework.
all data in all classes must be private.
if you declare an reference object, this object must be initialized with a new statement.
If you violate any of these additional requirements, you will receive 0 in this homework.
Hint : follow the "singleton" design pattern
One key issue in this homework it to apply the "singleton" design pattern. Singleton design pattern means you only have one instance created of a class type, and in this homework, you should create only one instance of the GreenfootSound class, which is the only music piece we are manipulating with play/pause button, and the volume up and down button. Then to manipulate this only instance among different classes/files, you need to resort to the encapsulation principle, and create public getter and/or setters for this object, so that other classes can reply on the public getter/setter to access this object.
One common mistake in this homework I have seen is: student creates separate instances of the GreenfootSound objects in different classes, and students fail to notice that these instances are independent of each other, for example, one instance of GreenfootSound object is to be controlled by the play/pause button, and the other instance is to be controlled by the volume up button, etc. Then the consequence is that: when you click the up button, you increase the volume of the GreenfootSound object, but the object whose volume you just increased has nothing to do with the GreenfootSound object that is being used by the play/pause button, which is a typical violation of the "singleton" design pattern.
The "singleton" principle also applies to other classes, such as, you should only create one instance for the play/pause button, and only one instance for the bar display, and only one instance for volume up button, and you should share one current volume variable among all different classes. If you have multiple variables indicating the sound object's current volume in difference classes, then you need to synchronized them, which means that if you increase or decrease the volume in one class, you need to populate the change to other classes where they also have a variable indicting the current volume level.
Notice: in class GreenfootSound, you should use its method setVolume(intlevel) to change the volume. When you call this method, you should plug in the desire volume level between 0 and 100.
In this homework, why we should not call the getVolume()method in class GreenfootSound?
Answer: because when any audio clip is played, the actual volume level changes at different segments of the sound track, as indicated by the vertical bar display of the volume in the picture below. The horizontal line is the time, and the vertical line is the actual volume of the sound tract.
Therefore, we cannot use the getVolume() method to retrieve the current average volume level, and since you cannot use method getVolume() to obtain the average volume level of the sound track being played, then you need to declare a private data member to store the current average volume level. And when the volume increase or volume decrease button is pressed, you need to modify the data that stored the current average volume, and then use method setVolume(intlevel)to set the modified average volume to the sound track. Also, pay attention to the valid data range of the volume that you can set.
Exercise 10.45 Make a new scenario for a (very simple) MP3 player. Create an actor for a start button. Place an MP3 file into the scenario's sound folder. Program it so that clicking the button starts playing the MP3 file. Clicking it while it is playing stops play- ing the file. Exercise 10.46 Make sure the button image changes: It should be the typical "play" triangle while the sound is not playing, and change to the usual "pause" symbol (dou- ble vertical bars) when it is playing. Exercise 10.48 Add two buttons to change the volume up and down. Exercise 10.49 Add a display that shows the current volume.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
To implement the described scenario you need to follow the instructions provided and ensure that you ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started