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
What are issues to consider when deciding to build software in-house or purchase commercial off-the-shelf software (cots)?
Scrat [10]
<span>On the computer there are always issues. For a developer to sit all day in front of a google that always invents things and the flashy images that disrupt everything. Googling on facebook is also an issue. Youtube, everything that contain flashy image is quite disruptive. If you think about content, maybe googling is less inventive. In a way it's nicer to buy applications but if you finally think of building it, there are always nicer ways of spending time. I prefer to go to seaside when I can.</span>
7 0
3 years ago
________ can contain stacked images, text, and other elements which collectively comprise a Photoshop file.
emmasim [6.3K]
If you don’t mind can u add the picture it helps me Answer the question better
6 0
2 years ago
For each of the following cases, select the type of NoSQL DBMS that would fit best the needs of the situation. a. The database h
ohaa [14]

Answer:

Check the explanation

Explanation:

(a) There will be a need for the database to support a comparatively complex and complicated hierarchical internal record structure that may vary for each record. Column store NoSQL DBMS

(b)The key requirements for the database are to access a specific record structure as quickly as possible without any concern regarding the internal structure of the record. Key value store NoSQL DBMS

(c) The data are specifically well suited to be organized as a network of connections amid the data items. Graph Base NoSQL DBMS

(d) It is essential that the DBMS offers quick access to each of the records by a key value, but, in addition, it has to also allow easy access to the components of each record. Document store NoSQL DBMS

4 0
3 years ago
Who benefits the most from billing by the second for cloud resources, such as virtual machines?.
scoundrel [369]

Clients that run numerous virtual machines.

<h3>What is a virtual machine?</h3>
  • A virtual machine is the virtualization or emulation of a computer system in computing.
  • The functionality of a physical computer is provided by virtual machines, which are built on computer architectures.
  • Their use may necessitate specialized hardware, software, or a combination of both.
  • Virtual machines' primary function is the simultaneous operation of several operating systems on a single piece of hardware.
  • Without virtualization, running two different physical units would be necessary to run different operating systems, such as Windows and Linux.
  • Through the use of virtualization technologies, virtual machines are made possible.
  • Multiple virtual machines (VMs) can run on a single machine thanks to virtualization, which simulates virtual hardware using software.
  • The real machine is referred to as the host, and any virtual machines running on it as the guests.

To learn more about virtual machines, refer to:

brainly.com/question/27961159

#SPJ4

7 0
1 year ago
AFLAC, Inc. recently implemented a company policy that all new IT projects must be coordinated and approved by the project manag
Shkiper50 [21]

Answer:

Option (E) is the correct answer to the following question.

Explanation:

Because it helps AFLAC Inc. company to run their project in a more easier way and it also helps its employees to work fast on their new IT projects by installing a WiFi network in their ALFAC inc. branch office. So, that's why they have to install a wireless network.

And the other option is not applied because these activities have to be done in all projects if the project is important either not.

8 0
3 years ago
Other questions:
  • Use a colon before a list and put one space after a colon. True False
    15·2 answers
  • major m,ajorrr points helpppppppppppppppppppppppppppi have a question i hit a few buttons and now my computer is saying everythi
    11·2 answers
  • Which is a function of network media?
    14·2 answers
  • Which devices are managed through device management?
    15·2 answers
  • For off campus work study positions, students should contact the
    6·1 answer
  • The instructions for a computer program are sometimes referred to as . computer programmers focus on computer programs, but they
    5·2 answers
  • A command, such as a button or keyboard shortcut, that performs a specific task is known as a
    9·2 answers
  • An IT security threat is anything that might cause serious harm to a computer system, including someone stealing a laptop that c
    8·2 answers
  • How can knowing internal and external parts of computer help me
    12·1 answer
  • What would the input, process, outcome and feedback be for a class assignment
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!