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
Fill in the blank. The process that a wireless router uses to translate a private IP address on internal traffic to a routable a
AleksandrR [38]

Answer:

Network Address Translation (NAT)

Explanation:

With the aid of Network address translation(NAT), the IP addresses of a particular local network are translated or mapped into a single or multiple global or public IP addresses. Therefore, a wireless router could use NAT to translate its private IP address on internal traffic (network) to a routable address for the internet.

With NAT, businesses can use many internal IP addresses since they are just for internal purposes and will be eventually converted into a single or a few multiple routable IP addresses.

Three types of NAT are possible:

(i) Static NAT : There is a one - to - one mapping between private IP addresses and routable (public) IP addresses. One private IP is mapped to one public IP address.

(ii) Dynamic NAT : There is a many- to - many mapping between private IP addresses and routable (public) IP addresses. Multiple private IPs are mapped to many public IP addresses.

(iii) Port Address Translation (PAT) : Many - to - one relationship between the private IP addresses and public addresses. Many private IP addresses can be mapped or translated into a single public IP address. This type of NAT is also called NAT overload.

6 0
3 years ago
Convert the decimal number -12 to hexadecimal (2's complement)
Helga [31]

Answer:

FFF4

Explanation:

Binary representation of 12 = 00001100

Expressing it in hexadecimal format : 0C

Binary representation of -12:

Step 1 : Computing 1's complement for 12 =11110011

Step 2 : Adding 1 to 1's complement to get the 2's complement =>

11110011+1 = 11110100

Converting the 2's complement representation to hexadecimal format:

F4 ( 8 bit representation) or FFF4 ( 16 bit representation)

4 0
3 years ago
___refers to self-acting or self-operating.
lisabon 2012 [21]

Answer:

do it to me watch this

Explanation:

trailing zeros in a whole number with no decimal shown are NOT significan

6 0
3 years ago
project-1 Write a class called Person that has two data members - the person's name and age. It should have an init method that
MArishka [77]
Hello how are you today
4 0
2 years ago
Can you run microsoft office on a chromebook
zimovet [89]
Yes, you can Microsoft office in a Chromebook.
6 0
3 years ago
Other questions:
  • To employ an access key, press and hold down the ____ key as you tap the access key.
    14·1 answer
  • Please help!! will fan and medal
    12·2 answers
  • Smart art can be used to create _____that highlights relationships betweeen two items
    8·2 answers
  • 100 points !!! Some games fall under more than one category. For example, many racing games allow players to modify the cars the
    8·2 answers
  • Write the definition of a method printDottedLine, which has no parameters and doesn't return anything. The method prints to stan
    12·1 answer
  • Gary has to complete a form before enrolling into an online course. A few of the fields require Gary to respond with either a "Y
    7·2 answers
  • An electronic tool that allows information to be input processed and output? A, operating system B.motherboard C.cpu D.computer
    11·1 answer
  • Write a program to compute the maximum and minimum value of three numbers:
    10·1 answer
  • HELP!!!!!!!
    8·1 answer
  • For 8.6 code practice: Question 1 It keeps says it's an infinite loop and it will not work can someone give me the code that wil
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!