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
Which recorder is least recommended in automation anywhere?
raketka [301]
<h2>Answer:</h2>

<u>Screen recorder</u><u> is the least recommended one</u>

<h2>Explanation:</h2>

There are three types of recorders. They are Smart Recorder, Web Recorder and Screen or sometimes called Standard Recorder. Smart Recorder is used for desktop applications while Web recorder is used for Web-based applications. The least recommended one is Screen Recorder which is used for building simple tasks that involves few mouse clicks and keystrokes. It works by capturing screen co-ordinates and therefore, no calibration is taken into account. It is generally used when you plan to run the task on the same machine on which, it was recorded.

4 0
3 years ago
Read 2 more answers
What are the important role that health care workers play in documentation, confidentially, maintenance and credibility of the m
Anna007 [38]
75. Health care workers are those persons who makes sure that they documented everything about their patient’s health problem. They also makes sure that they maintain those documentations and make sure the credibility and confidentially of an individual that undergone their care. It is their responsibility that this is keep confidential based on their patient’s request and also in their job’s duty. Once a health care worker divulge any confidential information, he or she can be given by a person a case in the court.
8 0
3 years ago
the block cipher attack technique that attempts to retrieve the key by performing decryption and encryption simultaneously on a
tankabanditka [31]

The block cipher attack strategy that attempts to retrieve the key by performing decryption and encryption simultaneously on a understood plaintext-ciphertext pair exists plaintext attack.

<h3>What is plaintext attack?</h3>

The known-plaintext attack is a type of cryptanalysis attack in which the attacker has access to both the encrypted and plaintext versions of the target data. These can be used to reveal additional hidden information, including code books and secret keys. An attack using known plaintext occurs when the attacker has access to pairs of known plaintexts and the ciphertexts that go with them.

The objective is to figure out the secret key (or keys) or to create an algorithm that would enable him to decrypt any additional messages. Ordinary readable text before it is converted into ciphertext in cryptography is known as plaintext, as is readable text that has been recovered from encryption. Not all data inputted into or outputted by encryption methods is plaintext.

Hence,  The block cipher attack strategy that attempts to retrieve the key by performing decryption and encryption simultaneously on a understood plaintext-ciphertext pair exists plaintext attack.

To learn more about cryptanalysis attack refer to:

brainly.com/question/19202523

#SPJ4

3 0
1 year ago
Write a program that reads the subtotal and the gratuity rate, then computes the gratuity and total.For example, if the user ent
lubasha [3.4K]

Answer:

Using Javascript,

function calTotal( subtotal, gratuity){

  gratuityValue = subtotal * (gratuity/100)

  total = subtotal + gratuityValue

  console.log( "gratuity: ", gratuityValue , "\nTotal: ", total)

}

Explanation:

The javascript function above is able to collect two parameters subtotal and gratuity rate in percentage and calculate the total and gratuity value, and displays it on the console.

8 0
3 years ago
What's wrong with these codes in code HS Karel challenges(7.1.2. Racing Karel) Codes: //Below is the program that have Karel mov
Viktor [21]

Answer:

The program only runs 5 five since the for loop statement is limited to loop only five times.

Explanation:

In programming, a for-loop statement is used to repeat a collection of events a definite number of times. The number of loops is specified and compared with a variable to execute a block of code.

The for-loop statement in the code above declares and initializes a variable "i" to zero, runs the block of code, and increments by one if it is less than 5.

To make it run eight times, the value five should be changed to 8 instead.

5 0
3 years ago
Other questions:
  • A _________ provides multiple ports for connecting nodes and is aware of the exact address or identity of all the nodes attached
    15·2 answers
  • The Distribute commands will evenly distribute the rows and columns within what? The width and height of the document. The width
    5·1 answer
  • if you want to present slide to fellow student or co-workers, wich productivity software should you use to create them?
    7·1 answer
  • Which one of the following statements referring to mobile Internet
    5·2 answers
  • Identify the characteristics of logic problems.select all that apply
    5·1 answer
  • To use an imported image, simply drag it from the desktop onto the stage. true or false
    15·2 answers
  • 1.Discuss the complexities of owning and sharing digital information.
    5·1 answer
  • A network technician attempts to ping www.example.net from a customer computer, but the ping fails. access to mapped network dri
    5·1 answer
  • Although plants and ainamals are both living things___
    13·1 answer
  • When you run your Windows Form application, what is the lifespan of a global variable (also known as a "field" or "class" variab
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!