Welcome to Westonci.ca, where finding answers to your questions is made simple by our community of experts. Get quick and reliable solutions to your questions from a community of seasoned experts on our user-friendly platform. Get immediate and reliable solutions to your questions from a community of experienced professionals on our platform.
Sagot :
Answer:
Explanation:
The following code is written in Java. It creates the Bug class with the position and direction variables. Then it creates a constructor, move method, turn method, and getPosition method. Finally, a bug object called bugsy is created in the main method, and we move it once to the right, then again to the right, and then we turn it and move it 5 times to the left, printing out the position when it is done moving. Output can be seen in the attached picture below.
class Brainly {
public static void main(String[] args) {
Bug bugsy = new Bug(10);
bugsy.move();
System.out.println("Current bug position: " + bugsy.getPosition());
bugsy.move();
System.out.println("Current bug position: " + bugsy.getPosition());
bugsy.turn();
bugsy.move();
bugsy.move();
bugsy.move();
bugsy.move();
bugsy.move();
System.out.println("Current bug position: " + bugsy.getPosition());
}
}
class Bug {
char direction = 'r';
int position = 0;
public Bug(int initialPosition) {
this.position = initialPosition;
}
public void turn() {
if (this.direction == 'r') {
this.direction = 'l';
} else {
this.direction = 'r';
}
}
public void move() {
if (this.direction == 'r') {
this.position += 1;
} else {
this.position -= 1;
}
}
public int getPosition() {
return this.position;
}
}
![View image sandlee09](https://us-static.z-dn.net/files/dc9/947c675ac8faf962827ff72f4a39091d.jpg)
In this exercise we want to use computer and Java knowledge to write the code correctly, so it is necessary to add the following to the informed code:
Output can be seen in the attached picture below
The following secret language system exist composed fashionable Java. It develop in mind or physically the bug class accompanying the position and direction variables. Then it develop in mind or physically a builder, move arrangement, turn means, and catch position procedure.
Finally, a bug object named bugsy happen develop in mind or physically usually pattern, and we fast once to the right, therefore another time to the right, and before we turn it and speedy 5 period to the abandoned, a process of reproduction out the position when it exist thoroughly cooked mobile. We have that:
class Brainly {
public static void main(String[] args) {
Bug bugsy = new Bug(10);
bugsy.move();
System.out.println("Current bug position: " + bugsy.getPosition());
bugsy.move();
System.out.println("Current bug position: " + bugsy.getPosition());
bugsy.turn();
bugsy.move();
bugsy.move();
bugsy.move();
bugsy.move();
bugsy.move();
System.out.println("Current bug position: " + bugsy.getPosition());
}
}
class Bug {
char direction = 'r';
int position = 0;
public Bug(int initialPosition) {
this.position = initialPosition;
}
public void turn() {
if (this.direction == 'r') {
this.direction = 'l';
} else {
this.direction = 'r';
}
}
public void move() {
if (this.direction == 'r') {
this.position += 1;
} else {
this.position -= 1;
}
}
public int getPosition() {
return this.position;
}
}
See more about computer at brainly.com/question/950632
![View image lhmarianateixeira](https://us-static.z-dn.net/files/d71/b2870b4fc8f8f1cfe8e7e31b471c41f1.png)
We hope you found this helpful. Feel free to come back anytime for more accurate answers and updated information. Thanks for stopping by. We strive to provide the best answers for all your questions. See you again soon. We're here to help at Westonci.ca. Keep visiting for the best answers to your questions.