1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Nadusha1986 [10]
3 years ago
7

Write a class Bug that models a bug moving along a horizontal line. The bug moves either to the right or left. Initially, the bu

g moves to the right, but it can turn to change its direction. In each move, its position changes by one unit in the current direction. Provide a constructor public Bug(int initialPosition) and methods public void turnC * public void move( °public int getPositionO Sample usage: Bug bugsy new Bug(10) bugsy.moveO; // Now the position is 11 bugsy.turnO bugsy.moveO; // Now the position is 10 Your main method should construct a bug, make it move and turn a few times, and print the actual and expected positions
Computers and Technology
1 answer:
Harrizon [31]3 years ago
7 0

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;

   }

}

You might be interested in
Conduct a site research on a specific property using the concepts discussed during this week.
Anni [7]

Answer:Penis!

Explanation:

Haha! Enjoy your day! Hahahahaha!

8 0
2 years ago
What is the purpose of system software?
suter [353]
"To preform specific useful computing tasks, like word processing and calculation" is the correct answer. This is the whole purpose of system software. The third answer is some other type of software(third party software?) and the fourth answer is most likely a compiler. Those are the easiest to take off. The second could also work.

The two answers I would go with are the first and the second.
8 0
3 years ago
2.5 code practice I need answers please
Leni [432]

Answer:

import random

a = random.randint(1,10)

b = random.randint(1,10)

answer = a * b

print (str(a) + " X " + str(b) + " = " + str(answer))

Explanation:

Happy to help you mate

7 0
3 years ago
Kiara is using her software's graphic formats to create a line graph. As she
Ad libitum [116K]

Correct the data she entered , and the software will adjust the graph -apex

5 0
3 years ago
Read 2 more answers
Identify the data link trailer blocker
IRINA_888 [86]
What are ur possible answers
7 0
3 years ago
Other questions:
  • What filter gives a “squeezed” effect to an image?
    14·2 answers
  • A star appears under the <br> menu of the word processing program.
    5·1 answer
  • After which stage in the information processing cycle can data be referred for future use?
    7·1 answer
  • What is not true about contracts?
    12·2 answers
  • What does my name look like in binary code, btw my mane is Wendy Alexis Morales
    10·2 answers
  • Which statement about muzzleloaders is true? All muzzleloaders are rifles. All muzzleloaders have only one barrel. Muzzleloaders
    12·1 answer
  • What are 5 good movies like The Breakfast Club or 8 Mile?
    14·2 answers
  • HELP PLX ITS PYTHON BTW!!!
    8·1 answer
  • Robyn needs to ensure that a command she frequently uses is added to the Quick Access toolbar. This command is not found in the
    11·1 answer
  • Of the following field which would be the most appropriate for the primary key in a customer information table?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!