Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This program will simulate the growth and decrease of bugs based on breeding the bugs and spraying the bugs. a. Create a Bug class b.

This program will simulate the growth and decrease of bugs based on breeding the bugs and spraying the bugs.

a. Create a Bug class

b. Create an instance variable to hold the number of bugs.

c. Create a constructor that sets the original number of bugs to an amount that is provided through the argument. Hint: BankAccount with an initial balance.

d. Create a method call breedBugs. This method will not return anything and will not have an argument. The breedBugs method should double the number of bugs each time it is invoked or called

e. Create a method called sprayBugs. This method will not return anything and will not have an argument. The sprayBugs should decrease the number of bugs by 1/4 each time it is invoked. Multiply the total bugs by .75. Your bugs should be integers because you do not have partial bugs. However, because we are dividing your result may be a double. To take care of this problem, put (int)(your formula) in your method. This is a cast. Be sure and put your formula in ().

f. Create a method to return the number of bugs.

g. Create a BugTester class

h. Create a main

i. Create a Bug object and begin with 10 bugs. Hint: Remember how you created a BankAccount Object with an initial balance.

j. Call / invoke the breedBugs method . Hint: Call deposit but no parameters.

k. Call the sprayBugs method 3 .

l. Print the number of bugs (The result should be an integer no half dead bugs)

m. Repeat j l two additional times. This means that you will breed, spray and print 3 times.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions