Java Programming: Mutator Method Assignment Q&A

Categories: Programming

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.

Get quality help now
Marrie pro writer
Marrie pro writer
checked Verified writer

Proficient in: Programming

star star star star 5 (204)

“ She followed all my directions. It was really easy to contact her and respond very fast as well. ”

avatar avatar avatar
+84 relevant experts are online
Hire writer

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.

Get to Know The Price Estimate For Your Paper
Topic
Number of pages
Email Invalid email

By clicking “Check Writers’ Offers”, you agree to our terms of service and privacy policy. We’ll occasionally send you promo and account related email

"You must agree to out terms of services and privacy policy"
Write my paper

You won’t be charged yet!

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 java. Util Random;
//random generator
Private Random rand;
rand = new Random();
public void play randomtrack
{
Int randomNumber = rand.Nextln (track.size());
playTrack(randomNumber)
}

Updated: Jul 06, 2022
Cite this page

Java Programming: Mutator Method Assignment Q&A. (2016, Mar 23). Retrieved from https://studymoose.com/java-programming-mutator-method-assignment-qa-essay

Java Programming: Mutator Method Assignment Q&A essay
Live chat  with support 24/7

👋 Hi! I’m your smart assistant Amy!

Don’t know where to start? Type your requirements and I’ll connect you to an academic expert within 3 minutes.

get help with your assignment