[Assessment 2(16): You must have this exercise signed off by your class supervisor]
On paper, write a method called sum with a while loop that adds up all numbers between two numbers a and b, inclusive, and returns the sum as its result. The values for a and b can be passed to the sum method as parameters. For instance: sum(1, 5) would return the value 15 (i.e., 1 + 2 + 3 + 4 + 5).
What happens if the value of the second parameter is less than the value of the first?
public int Sum (int a, int b) { int sum = 0; while (a < b) { sum += a; a++; }
Sum += b; return sum ;
}
Exercise 4.37
[Assessment 2(17): You must have this exercise signed off by your class supervisor]
Add a further field, of your choosing, to the Track class, and provide accessor and mutator methods to query and manipulate it. Find a way to use this information in your version of the project; for instance, include it in a track’s details string, or allow it to be set via a method in the MusicOrganizer class.
Public Music organizer ()
{
Track = new Arraylist ();
Player = new Music player ();
Reader = new TrackReader ();
Edit = new EditTrack ();
Read Library (“audio”);
Systems.out.println (“Music library loaded.” + get Number of Track + “tracks.”);
System.out.println();
}
{
Public void edit Track (track)
Trackedit (track);
}
Exercise 4.43
[Assessment 2(18): You must have this exercise signed off by your class supervisor]
The java.util package contains the Random class whose nextInt method will generate a positive random integer within a limited range. Write a method in the MusicOrganizer class to select a single random track from its list and play it.
Hint: You will need to import Random and create a Random object, either directly in the new method or in the constructor and stored in a field. You will need to find the API documentation for the Random class and check its methods to choose the correct version of nextInt.
Import