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
______was developed as an interim management protocol with OSI as the ultimate network management protocol.
RSB [31]

Answer:

Simple Network Management Protocol

Explanation:

Simple Network Management Protocol otherwise referred to as SNMP is a form of computer protocol that is mainly used in obtaining and regulating information relating to connected gadgets. It is practically based on the internet and was originally planned as an interim protocol.

Hence, it can be concluded that the Simple Network Management Protocol was developed as an interim management protocol with OSI as the ultimate network management protocol.

4 0
3 years ago
Thomas Edison and his assistant W. K. L. Dickson patented which device in 1891
Svetlanka [38]
They patented the kinetoscope
5 0
3 years ago
Read 2 more answers
Which programming language uses objects? C++ ALGOL Pascal BASIC
svetlana [45]

Answer:

C++

Explanation:

I am a c++ dev

7 0
3 years ago
Read 2 more answers
How do we distinguish between remote and local information sources? give an example of each source? i'll give brainliest answer
kirill [66]

A local server means that you have a server setup on your current machine. A remote server is ran on a different machine

7 0
2 years ago
1. PGP encryption can be performed from the command line as well. What is the PGP command line syntax to encrypt the my-message.
bekas [8.4K]

Answer:

1. From the command prompt, type:

pgp --encrypt "my-message.txt" --recipient "Sean" --output "secret-message.txt.gpg"

2. Press Enter.

Explanation:

From the command line, the above command is entered and Enter is pressed.

The command start with pgp, then it has different options:

--encrypt: this specifies the input file to be encrypted

--recipient: this specifies the specific user to which the file is been encrypted

--output: this specifies the name to which the output (encrypted file) is saved.

8 0
3 years ago
Other questions:
  • Consider the attack scenario given below:
    8·1 answer
  • Forms open in _______, which provides a user-friendly interface for entering data.
    11·1 answer
  • What is really meant by SSDs
    9·1 answer
  • In today's classrooms, computers are generally being used to
    6·1 answer
  • Assuming 8-bit 2's complement notation, what is the result of subtracting 00001001 from 00001101?
    11·1 answer
  • PLEASE HELP!
    14·2 answers
  • What is the term used to describe the basic unit of data passed from one computer to another
    14·1 answer
  • QUESTION 10
    10·2 answers
  • What is the significance of the scientific method?
    6·1 answer
  • Is there an air flow through the house? if so, does the air flow in the window and out the chimney, or in the chimney and out th
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!