Question: a. Copy the Bug class from Lab4. You do not need to make an alterations to it. ( In bold below ) b. Create a

a. Copy the Bug class from Lab4. You do not need to make an alterations to it. (In bold below)

b. Create a tester class named BugTester

c. Create a main method

d. Create a Bug object with 10 as the argument

e. In a loop, breed the bugs 4 times.

f. In a loop, spray the bugs 4 times.

g. Print the result.

public class BugTester { // instance variables - replace the example below with your own private int x;

/** * Constructor for objects of class BugTester */ public BugTester() { // initialise instance variables x = 0; }

/** * An example of a method - replace this comment with your own * * @param y a sample parameter for a method * @return the sum of x and y */ public int sampleMethod(int y) { // put your code here return x + y; } }

Breed and Spray came from this code: (In Italics)

public class Bug { private int totalBugs; public Bug() { totalBugs = 0; } public Bug(int initialBugs) { totalBugs = initialBugs; } public void breedBugs() { totalBugs = 2 * totalBugs; } public void sprayBugs() { totalBugs = (int)(totalBugs * .75); } public int returnTotal() { return totalBugs; } }

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 Databases Questions!