Question: Create a class named Dust. Create another class named Dustpan. Declare two member variables. The first member variable is named count of type int. The

Create a class named Dust.
Create another class named Dustpan. Declare two member variables. The first member variable is named count of type int. The second variable is an array of type Dust named dustParticles.
Add a constructor with a single parameter of type int named size. The size is used to initialize the array with the given size.
Add two methods. The first method named add expects a single argument of type Dust. It adds the dust object to the next available position in the dustParticles array. Use the count variable to determine the next available spot and subsequently increment it. Define a second method named empty. It does not have any parameters. This method empties the dustParticles array by using a loop to set each element to null.
Create a class named Broom with a single method named sweep. The sweep method expects two parameters of type Dustpan and Dust. The method adds the dust to the dustpan using the Dustpan's add method.
Declare a main function. In the main create a broom. Next, create a Dustpan of size 5. Then create an array of Dust particles of size 5 named dustpile. Use a for-each loop to iterate of the dustpile array. In each iteration call the sweep method of the broom to sweep up the dust. Finally, after the loop empty the dustpan using the same named method.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!